Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-27-2018, 01:30 PM
RMerckling RMerckling is offline Excel VBA - Select All in Word Doc & Update Fields Windows 7 64bit Excel VBA - Select All in Word Doc & Update Fields Office 2010 32bit
Novice
Excel VBA - Select All in Word Doc & Update Fields
 
Join Date: Jan 2018
Posts: 29
RMerckling is on a distinguished road
Default Excel VBA - Select All in Word Doc & Update Fields

Hey all,

Attempting to get the bottom portion of this code to work in Excel VBA, I took the language from Word VBA so not sure how well it translates

ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument

Receiving an error "Runtime error '438': Object doesn't support this property or method"

Code:
Sub CopyandRename()
    Dim str1 As String
    str1 = "Q:\IC\New Structure\IC Toolkit\Templates\01 Plan Doc Template\16 Source\IC Plan Doc Template v1.0.docx"
    PlanDocTemplate = Application.ActiveWorkbook.Path & "\" & Range("A1").Value & ".docx"
    
    Call FileCopy(str1, PlanDocTemplate)
    
    strWorkbookName = ThisWorkbook.Path & "\" & ThisWorkbook.Name
    Worksheets("Data").Activate
       
'Opens New Plan Doc Template

    Set appWD = CreateObject("Word.Application")
    appWD.Visible = True

    appWD.Documents.Open Filename:=PlanDocTemplate
    
    ActiveDocument.MailMerge.OpenDataSource Name:=strWorkbookName, _
    Format:=wdMergeInfoFromExcelDDE, _
    ConfirmConversions:=True, _
    ReadOnly:=False, _
    LinkToSource:=True, _
    AddtoRecentFiles:=False, _
    PasswordDocument:="", _
    PasswordTemplate:="", _
    Revert:=False, _
    Connection:="Entire Spreadsheet", _
    SQLStatement:="SELECT * FROM `Data$`", _
    SQLStatement1:="", _
    SubType:=wdMergeSubTypeOther
    
    appWD.Visible = True

    appWD.Selection.WholeStory
    appWD.Selection.Fields.Update
    appWD.Selection.Fields.Unlink
    appWD.ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument
    appWD.ActiveDocument.Save

End Sub
The code is intended to change the newly merged Word Document into a regular word document.



Any help is greatly appreciated, thanks,
Rich
Reply With Quote
  #2  
Old 04-27-2018, 01:47 PM
RMerckling RMerckling is offline Excel VBA - Select All in Word Doc & Update Fields Windows 7 64bit Excel VBA - Select All in Word Doc & Update Fields Office 2010 32bit
Novice
Excel VBA - Select All in Word Doc & Update Fields
 
Join Date: Jan 2018
Posts: 29
RMerckling is on a distinguished road
Default Solved - Disregard

Changed appWD to "ActiveDocument" on that line and it worked.

Thanks.
Reply With Quote
Reply

Tags
excel vba, mail merge, word vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word document with VBA and Form Fields reset when select File,Print fatal.lordes Word VBA 9 04-27-2018 11:30 PM
How to update Word 2016 custom mail merge fields in bulk? dorian Mail Merge 1 09-23-2017 02:03 AM
Excel VBA - Select All in Word Doc & Update Fields Macro to select and update all tables in document CircleG Word VBA 6 10-17-2014 07:25 PM
Excel VBA - Select All in Word Doc & Update Fields Open Word w Excel & fill Word textboxes w info from Excel fields runtime error 4248 Joe Patrick Word VBA 2 01-30-2012 07:23 AM
Does Word have an option to update fields AUTOMATICALLY at open??? Jamal NUMAN Word 17 01-27-2012 12:57 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:28 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft