- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear community,
I'm seeking assistance as I'm encountering difficulty with a task involving a VBA macro.
The objective is to search and select a Word document using the macro. Once the document is selected, it should open automatically, and the text within it should be copied to the clipboard. Subsequently, this copied text should be inserted into the 'comment' property.
However, I've encountered a problem. The code provided below successfully enables the selection of a document. Yet, I'm unsure how to proceed with opening Word and completing the subsequent steps.
I've attempted solutions suggested by ChatGPT, but they haven't yielded satisfactory results and have generated numerous error messages.
Any guidance or assistance would be greatly appreciated.
I use the Code below in an User form.
Private Sub Suche_Click()
' Create a new FileDialog object.
Dim oFileDlg As fileDialogCall ThisApplication.CreateFileDialog(oFileDlg)
' Define the filter to select part and assembly files or any file.
oFileDlg.Filter = "Word files (*.doc;*.docx)|*.doc;*.docx|All Files (*.*)|*.*"
' Define the part and assembly files filter to be the default filter.
oFileDlg.FilterIndex = 1
' Set the title for the dialog.
oFileDlg.DialogTitle = "Open File Test"
' Set the initial directory that will be displayed in the dialog.
oFileDlg.InitialDirectory = "This PC"
' Set the flag so an error will be raised if the user clicks the Cancel button.
oFileDlg.CancelError = True
' Show the open dialog. The same procedure is also used for the Save dialog.
' The commented code can be used for the Save dialog.
On Error Resume Next
oFileDlg.ShowOpen
' oFileDlg.ShowSave
' If an error was raised, the user clicked cancel, otherwise display the filename.
If Err Then
MsgBox "User cancelled out of dialog"
ElseIf oFileDlg.FileName <> "" Then
MsgBox "File " & oFileDlg.FileName & " was selected."
End If
End Sub
Solved! Go to Solution.