Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 02-09-2021, 01:32 AM
Bumba Bumba is offline How to add date from excel to word document header? Windows 7 32bit How to add date from excel to word document header? Office 2007
Novice
How to add date from excel to word document header?
 
Join Date: Jan 2019
Posts: 26
Bumba is on a distinguished road
Default

Something like this,

Code:
Dim wrdApp          As Object, wrdDoc As Object
On Error Resume Next
Set wrdApp = GetObject(Class:="Word.Application")

If wrdApp Is Nothing Then
    Err.Clear
    Set wrdApp = CreateObject(Class:="Word.Application")
    
    If wrdApp Is Nothing Then
        MsgBox "Microsoft Word could Not be found - Aborting"
        Exit Sub
    End If
End If
On Error GoTo 0
Application.ScreenUpdating = FALSE
Application.EnableEvents = FALSE
With wrdApp
    .Application.ScreenUpdating = FALSE
    Set wrdDoc = .Documents.Open("D: \08-02-21\test.docx")
    .Visible = TRUE
    .Activate
    
    Dim HdrText     As String
    Dim BoldRange   As Range
    Dim HdrRange    As Range
    
    'Set Variable equal to Header Range
    Set HdrRange = wrdDoc.Sections.Item(1).Headers(wdHeaderFooterPrimary).Range
    
    ‘Data To add To Header
    HdrText = ThisWorkbook.Sheets("details").Cells(4,2).Value
    
    'Add Text To Word Header
    HdrRange.Text = HdrText
    
    'Bold Only First Sentence in Header
    Set BoldRange = HdrRange.Words(1)        'Get First Word
    BoldRange.Expand (wdSentence)        'Expand To Entire Sentence
    BoldRange.Font.Bold = TRUE        'Bold Entire Sentence
End With
But getting error at wdHeaderFooterPrimary.

Also, I'm new to this kind of thing and I have not done word doc manipulation from excel.
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract Document ID and description from header in multiple Word documents and paste in new word doc venkat_m Word VBA 2 05-23-2020 03:57 AM
How to add date from excel to word document header? Calculate week in Word document based on date entered into same document ArviLaanemets Word VBA 4 11-18-2019 12:25 AM
Document attached to Word Header MidgesMom Word 0 11-13-2018 10:58 AM
Convert csv document to excel, format date coba Excel Programming 3 01-07-2016 04:18 AM
How to add date from excel to word document header? word 2007 - Inserting value in the document header chamdan Word VBA 7 11-15-2013 05:06 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:44 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