Hi All
I have a macro that I run in Outlook. At the end of that macro there is this code:
I am wondering if there is some code I can put into the "With word" block that would write the "job" variable into the Word document, and then some Word VBA code to read this "job" variable for use inside some Word macros saved in the Template.docm file that this code is opening.
I don't have any idea how to write this, but something like this mock code:
And then in the Template.docm file a macro would be something like this:
Is anything like this possible? I imagine (though I haven't tested it) that it would be possible in excel by using something like "Excel.Sheets("Sheet1").Range("A1") = job" and then in excel "job = Sheets("Sheet1").Range("A1")" or something similar, but don't have any idea how/if its possible with word and outlook?
Thanks in advance.
With a little googling I found this: HeadersFooters Object (Word) using the second vba example could I use something like the below in my Outlook code:
I have tried various positions of the this in:
But nothing has worked so far??
Cheers
I have a macro that I run in Outlook. At the end of that macro there is this code:
Code:
job = ImputBox("Enter Job Number")
Dim word As Object
Set word = CreateObject("Word.Application")
Template = "C:\Users\tbaker\Documents\Template.docm"
With word
.Visible = True
.Application.Activate
.Documents.Open (Template)
End With
I am wondering if there is some code I can put into the "With word" block that would write the "job" variable into the Word document, and then some Word VBA code to read this "job" variable for use inside some Word macros saved in the Template.docm file that this code is opening.
I don't have any idea how to write this, but something like this mock code:
Code:
With word
.Visible = True
.Application.Activate
.Documents.Open (Template)
.Write.Header = job 'made up code haha I have no idea what the code would actually be but you get the idea
End with
And then in the Template.docm file a macro would be something like this:
Code:
Sub readjob()
Dim job As String
job = Header.Value 'Completely made up code but you get the idea, its passing the variable from Outlook into Word via writing it in the word document and then VBA reading it again into a variable in Word
Is anything like this possible? I imagine (though I haven't tested it) that it would be possible in excel by using something like "Excel.Sheets("Sheet1").Range("A1") = job" and then in excel "job = Sheets("Sheet1").Range("A1")" or something similar, but don't have any idea how/if its possible with word and outlook?
Thanks in advance.
With a little googling I found this: HeadersFooters Object (Word) using the second vba example could I use something like the below in my Outlook code:
Code:
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = job
I have tried various positions of the this in:
Code:
job = ImputBox("Enter Job Number")
Dim word As Object
Set word = CreateObject("Word.Application")
Template = "C:\Users\tbaker\Documents\Template.docm"
With word
.Visible = True
.Application.Activate
.Documents.Open (Template)
End With
But nothing has worked so far??
Cheers