VBA-选择保存文件的目标文件夹

VBA-选择保存文件的目标文件夹,vba,ms-word,Vba,Ms Word,我是个彻头彻尾的VBA迷,需要一点帮助。如果重要的话,我正在Mac上使用Microsoft Word 2016。我正在使用邮件合并创建word文档,需要根据分节符将生成的word文档拆分为多个页面。我找到了一个带有VBA代码的页面来分割页面,效果非常好。我唯一的问题是它保存到我计算机上的一个随机位置(我不知道它是如何决定保存到哪里的)。以下是我正在使用的代码: Sub BreakOnSection() ' Used to set criteria for moving throu

我是个彻头彻尾的VBA迷,需要一点帮助。如果重要的话,我正在Mac上使用Microsoft Word 2016。我正在使用邮件合并创建word文档,需要根据分节符将生成的word文档拆分为多个页面。我找到了一个带有VBA代码的页面来分割页面,效果非常好。我唯一的问题是它保存到我计算机上的一个随机位置(我不知道它是如何决定保存到哪里的)。以下是我正在使用的代码:

Sub BreakOnSection()     
   ' Used to set criteria for moving through the document by section.     
   Application.Browser.Target = wdBrowseSection     

   'A mail merge document ends with a section break next page.     
   'Subtracting one from the section count stop error message.     
   For i = 1 To ((ActiveDocument.Sections.Count) - 1)     

'Note: If a document does not end with a section break,     
'substitute the following line of code for the one above:     
'For I = 1 To ActiveDocument.Sections.Count     

      'Select and copy the section text to the clipboard.     
      ActiveDocument.Bookmarks("\Section").Range.Copy     

      'Create a new document to paste text from clipboard.     
      Documents.Add     
      Selection.Paste     

   ' Removes the break that is copied at the end of the section, if any.     
      Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend     
      Selection.Delete Unit:=wdCharacter, Count:=1     
ChangeFileOpenDirectory "C:\"     
      DocNum = DocNum + 1     
     ActiveDocument.SaveAs fileName:="test_" & DocNum & ".doc"     
     ActiveDocument.Close     
      ' Move the selection to the next section in the document.     
     Application.Browser.Next     
   Next i     
   ActiveDocument.Close savechanges:=wdDoNotSaveChanges     
End Sub
我看到ChangeFileOpenDirectory被设置为“C:\”,这对于mac来说是不合适的,但是我需要做什么更改才能让它问我在哪里保存所有生成的文档?我不想为每个单独的文档选择一个文件夹,而是为所有要保存到的文档选择一个文件夹并让它运行。
提前感谢您的帮助,我已经尝试了几个小时的谷歌,但仍然不确定这一点。

我还没有在mac上测试过,但应该是

Dim mySaveLocation As String
Dim dlg As FileDialog

Set dlg = Application.FileDialog(msoFileDialogFolderPicker)
dlg.AllowMultiSelect = False
dlg.Show
mySaveLocation = dlg.SelectedItems.Item(1)
然后当你保存它的时候

ActiveDocument.SaveAs fileName:= mySaveLocation  & "\test_" & DocNum & ".doc"

我还没有在mac电脑上测试过,但应该是

Dim mySaveLocation As String
Dim dlg As FileDialog

Set dlg = Application.FileDialog(msoFileDialogFolderPicker)
dlg.AllowMultiSelect = False
dlg.Show
mySaveLocation = dlg.SelectedItems.Item(1)
然后当你保存它的时候

ActiveDocument.SaveAs fileName:= mySaveLocation  & "\test_" & DocNum & ".doc"