View Single Post
 
Old 10-17-2023, 08:57 PM
syl3786 syl3786 is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: Jan 2023
Posts: 97
syl3786 is on a distinguished road
Question How to extract Excel data for Word Macro?

Hi everyone,

I would like to ask how to add some codes to the following code, so that the following macro can extract Excel data, Text = "[0-9]{6}" for Word Macro.

Code:
Private strWB As String
Private strSheet As String
Sub ReplaceHLink()

strWB = BrowseForFile("Select Workbook", True)
If Not strWB = vbNullString Then

strSheet = "Time"

End With
End If

End Sub
Private Function BrowseForFile(Optional strTitle As String, Optional bExcel As Boolean) As String
Dim fDialog As FileDialog
    On Error GoTo ERR_HANDLER
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    With fDialog
        .Title = strTitle
        .AllowMultiSelect = False
        .Filters.Clear
        If bExcel Then
            .Filters.Add "Excel workbooks", "*.xls,*.xlsx,*.xlsm"
        Else
            .Filters.Add "Word documents", "*.doc,*.docx,*.docm"
        End If
        .InitialView = msoFileDialogViewList
        If .Show <> -1 Then GoTo ERR_HANDLER:
        BrowseForFile = fDialog.SelectedItems.item(1)
    End With
lbl_Exit:
    Exit Function
ERR_HANDLER:
    BrowseForFile = vbNullString
    Resume lbl_Exit
End Function
Reply With Quote