Define a constant

  • Thread starter Thread starter leitek.com
  • Start date Start date
L

leitek.com

Hi there,

I need to define a constant path where excel files are to be saved.
this will allow me to change the constant path in case I need to change
where the files are to be saved vs. having to change the code line by
line to reflect the correct path.

' CODE STARTS HERE

Sub SaveFile()

dim myfolder as string

myfolder = "\servername\folder\filename.xls"

Windows("filename.xls").Activate

ActiveWorkbook.SaveAs Filename:=_
"myfolder\filename.xls"

ActiveWindow.Close

End Sub
'********************************************************************************

I also like to bypass the confirmation pop up box that comes up to
confirm the save, can this be done?

thanks for all your help.

salooha
 
Constants are declared at the top of the code module something like this

public const cFilePath as sting = "\servername\folder\"
public const cFileName as sting = "filename.xls"

Sub SaveFile()

dim myfolder as string

myfolder = "\servername\folder\filename.xls"

Windows(cFileName ).Activate

application.displayalerts = false
ActiveWorkbook.SaveAs Filename:=_
cFilePath & cFileName
application.displayalerts = true

ActiveWindow.Close

End Sub
 
Sub SaveFile()

Const myfolder as string = "\servername\folder\filename.xls"

Windows("filename.xls").Activate

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= myfolder
Application.DisplayAlerts = True

ActiveWindow.Close

End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
I used Bob's solution and it worked perfect.

thanks guys. I appreciate it.

salooha
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top