I have a macro that I run in Outlook. At the end of that macro there is this 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:
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:
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.