Consulting

Results 1 to 7 of 7

Thread: Macro to bring Excel data into Word template

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Macro to bring Excel data into Word template

    I'm having trouble with the below Macro. This is used to find information in an excel worksheet and use that info to fill in a word template. We used this in the past (2019ish) and it ran just fine, but now I either get a "Run Time Error 5852," or it just crashes Word. I ran the debugger and the bolded line seems to be causing this. I've tried linking the excel file as the MailMerge source, but that didn't work either. I didn't write this and I'm pretty new to macros, so I'm not sure how else to trouble shoot this.

    Sub Outage
    Dim dsMain As MailMergeDataSource, Ticker As String
    Ticker = InputBox("Enter the Ticker:")
    With ActiveDocument.MailMerge.DataSource
        Do While .FindRecord(FindText:=Ticker, Field:="Ticker") = True
            If .DataFields("Ticker") = Ticker Then
                numRecord = .ActiveRecord
                Exit Do
            End If
        Loop
    End With
    End Sub
    Last edited by Aussiebear; 05-09-2023 at 01:01 PM. Reason: Added code tags to supplied code

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •