簡體   English   中英

使用VBA在Excel中打開Microsoft Word文檔

[英]Open Microsoft Word Document in Excel with VBA

我試圖在Excel中打開Word文檔,以便將大量信息轉儲到其中。 我正在使用以下代碼:

   'Declare a variable as a FileDialog object and create a FileDialog object as a File Picker dialog box
    Dim iFileSelect As FileDialog
    Set iFileSelect = Application.FileDialog(msoFileDialogFilePicker)

    'Declare a variable to contain the path of each selected item
    Dim vrtSelectedItem As Variant


    'Use the Show method to display the File Picker dialog box
    'The user pressed the action button
     If iFileSelect.Show = -1 Then

     For Each vrtSelectedItem In iFileSelect.SelectedItems
     'vrtSelectedItem contains  path of each selected item
     MsgBox "The path is: " & vrtSelectedItem
     Next vrtSelectedItem

     End If

    'Set object variable to Nothing
    Set iFileSelect = Nothing

我遇到以下問題:

  1. 我不知道文件是否真的打開過。
  2. 將信息轉儲到文件后,如何關閉並保存文件?

如果您有在Excel中打開的工作簿,則可以使用其FollowHyperlink方法打開文檔。

Sub OpenDoc()
    Dim iFileSelect As FileDialog
    Set iFileSelect = Application.FileDialog(msoFileDialogFilePicker)

    Dim vrtSelectedItem As Variant

    If iFileSelect.Show = -1 Then
        For Each vrtSelectedItem In iFileSelect.SelectedItems
            ActiveWorkbook.FollowHyperlink vrtSelectedItem
        Next vrtSelectedItem
    End If

    Set iFileSelect = Nothing
End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM