Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-01-2013, 08:40 PM
stildawn stildawn is offline VBA to write into a Word doc from Outlook, then have Word VBA read what was written? Windows 7 64bit VBA to write into a Word doc from Outlook, then have Word VBA read what was written? Office 2010 64bit
Novice
VBA to write into a Word doc from Outlook, then have Word VBA read what was written?
 
Join Date: Aug 2013
Posts: 1
stildawn is on a distinguished road
Default VBA to write into a Word doc from Outlook, then have Word VBA read what was written?

Hi All

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
Reply With Quote
  #2  
Old 09-29-2013, 10:04 PM
macropod's Avatar
macropod macropod is offline VBA to write into a Word doc from Outlook, then have Word VBA read what was written? Windows 7 32bit VBA to write into a Word doc from Outlook, then have Word VBA read what was written? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi stildawn,

Basically:
Code:
With word 
    .Visible = True
    .Application.Activate 
    .Documents.Open (Template) 
    .ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.InsertBefore job
End With
Since you already have the 'job' variable, though, I don't see any value in having another macro retrieve it from the header. Why not simply continue using the same variable?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening files with MS Word using URL with IIS 6 for read AND write. wyattbiker Word 0 03-21-2013 07:32 AM
Blogs Written With Word Not Posting to Wordpress hpfan1972 Word 0 02-05-2013 04:48 PM
VBA to write into a Word doc from Outlook, then have Word VBA read what was written? Read text Report file with VBA and write parsed fields to Excel workbook tpcervelo Excel Programming 1 01-05-2012 10:14 PM
VBA to write into a Word doc from Outlook, then have Word VBA read what was written? How to write a table of contents in word ugurkocak1980 Word 4 05-31-2010 06:10 AM
How to write in Word from Select query lakhan.p Word 0 03-27-2009 07:25 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:01 PM.


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