WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Excel
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Set Excel Default Path on Start-up


Question:

i want to change the default file save locations used by Excel, Word, etc. I can do it using a macro, but i would prefer getting directly to the spot where the info is kept in the first place. I tried various searches of the DB and found nothing pertinent.

Answer:

;/////////////////////////////////////////////////////////
;// Winbatch - Set Excel Default Path on start-up
;//            Excel Security Options must be set to accept VB macros
;//
;// stan littlefield, December 22, 2003
;/////////////////////////////////////////////////////////

cFile          = StrCat( dirget(),"xldefa.bas")
If FileExist( cFile ) Then  FileDelete(cFile)

gosub ask
BoxOpen("Please Wait..","Loading in-Process Excel Macro")
;// don't show Excel yet.
DB               = ObjectOpen("Excel.Application")
DB.Visible       = @FALSE
DB.UserControl   = @FALSE
DB.DisplayAlerts = @FALSE
oAPP = DB.Workbooks
oAPP.Add()

oACT = DB.ActiveWorkbook
oWKS = DB.Worksheets
oWS  = DB.Worksheets(1)
oWS.Activate
;// if you get an OLE error on the next line, it is probably
;// a security issue
oVBE = DB.VBE
oPro = oVBE.ActiveVBProject
oCom = oPro.VBComponents
oCom.Import( cFile )
ObjectClose(oCom)
ObjectClose(oPro)
ObjectClose(oVBE)
;// execute the Macro prior to opening the WorkSheet
DB.Run("Defa")
BoxShut()
ObjectClose(oWS)
ObjectClose(oACT)
ObjectClose(oAPP)
; important to close Excel, changes take place on next start-up
DB.Quit()
ObjectClose(DB)
; delete .bas file just created or comment to keep
If FileExist( cFile ) Then  FileDelete(cFile)
message("Excel Default Path Set To",cPath)
Exit

:ask
; macro file could already exist, you could use INI entry, whatever
; you could add a lot more, such as default font, user name
cPath = Askline("Enter Default Excel Path","Path","")
cText = StrCat("Public Sub Defa()",@CRLF)
cText = StrCat(cText,"With Application",@CRLF)
cText = StrCat(cText,'.DefaultFilePath = "',cPath,'"',@CRLF)
cText = StrCat(cText,"End With",@CRLF)
cText = StrCat(cText,"End Sub",@CRLF)
FilePut(cFile,cText)
Return
;/////////////////////////////////////////////////////

Article ID:   W16108
File Created: 2004:03:30:15:42:54
Last Updated: 2004:03:30:15:42:54