FrisoKoopmanAarding
New Member
- Joined
- Feb 29, 2016
- Messages
- 4
Hi MrExcel,
With a macro in Excel I open up a word document from a word template. In this document I have a header which has two named logo's (named through Home->Editing (subsection on the right)-> Select->Selection Pane.... I would like to delete one of these logo's rather than generating two templates for each, as one template is easier to maintain. Also I might need to add more logo's in the future.
The code works fine in Word VBA, but not in Excel. After extensive searching on the web I figures out i might have something to do with late or early binding / object libraries?
Code in Word:
Code in Excel:
If anyone spots the error or know's a good workaround which still provides a single word file to maintain.
Regards Friso
With a macro in Excel I open up a word document from a word template. In this document I have a header which has two named logo's (named through Home->Editing (subsection on the right)-> Select->Selection Pane.... I would like to delete one of these logo's rather than generating two templates for each, as one template is easier to maintain. Also I might need to add more logo's in the future.
The code works fine in Word VBA, but not in Excel. After extensive searching on the web I figures out i might have something to do with late or early binding / object libraries?
Code in Word:
Code:
Selection.HeaderFooter.Shapes("Logo1").Select
Selection.ShapeRange.Delete
Code in Excel:
Code:
Sub Data2Word()
Dim WDApp As Object
Dim WDDoc As Object
Dim myWordFile As String
myWordFile = Sheets("1").Range("Quote_template_path").TextSet WDApp = CreateObject("Word.Application")
Set WDDoc = WDApp.Documents.Add(Template:=myWordFile)
WDApp.Visible = True
WDDoc.ActiveWindow.WindowState = wdWindowStateMaximize
If Sheets("Summary").Range("Letterhead").Value = 1 Then
WDApp.Activate
WDApp.Selection.HeaderFooter.Shapes("Logo1").Select
Selection.ShapeRange.Delete
If anyone spots the error or know's a good workaround which still provides a single word file to maintain.
Regards Friso