如何让用户从VBA中的特定位置打开文件?

我已经想出了如何打开浏览选项,以允许用户select一个他们想在代码稍后打开的文件,但我希望浏览器自动打开文件所在的特定文件夹。

我该怎么做呢? 目前默认打开我的文档文件夹,我想要打开"S/:CHEM Reports".的代码"S/:CHEM Reports".

这是我迄今为止所尝试的…

 spec_chems = Application.GetOpenFilename(Title:="Specialty Chems") If spch = False Then End Set spch = Application.Workbooks.Open(spec_chems) With spch .AllowMultiSelect = False .InitialFileName = "S:\CHEM Reports" .Activate End With 

调用对话框之前更改当前目录:

 ChDrive "S" ChDir "S:\CHEM Reports" spec_chems = Application.GetOpenFilename(Title:="Specialty Chems") If spec_chems = False Then End Set spch = Application.Workbooks.Open(spec_chems) 

我经常会将一个stringvariables定义为文件path,然后将文件path与我想要打开的文件连接起来。 我也可以将其他工作簿保存到我定义的文件path。

  fPath = "C:\Users\myusername\Desktop\Helpothers" sourcefname = fPath & "\" & fileID & ".xlsx" Application.Workbooks.Open (sourcefname) 

fileID是我想要打开的文件的名称。