Variables between Excel and Word Macros?

ectoid

Board Regular
Joined
Jan 18, 2005
Messages
97
Hello,
I am writing an Excel macro that includes a Word marco which opens an existing Word document.
The word document contains 3 tables. The 3rd table is a template that will be copied x-number of times based on a value in the Excel spreadsheet...lets call that Excel variable SheetNum.

I can define, calculate and set SheetNum in Excel without a problem.
How do I then call SheetNum within the Word macro such that it understands the Excel defined variable?

Thanks.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
I suggest you do the whole thing in Excel. You can create a Word object in VBA from any office application. Just do a search for "Word automation" and you should turn up a few thousand suggestions! ;)

PS - the one thing these pages often forget to tell you about is "references". In the VB editor behind Excel select "Tools" then "References". Find "Microsoft Word ... Object Library" and tick the box next to that. Then you're rockin n rollin.
 
Upvote 0
Yeah, I've got the word object created and referenced accordingly within my Excel macro...no worries there.
The problem is, I need to have the Word marco (as written within Excel) create a number of tables based on an Excel variable.
I guess, I don't know the syntax within the Word VB to appropriately call the Excel dimensioned variable.
 
Upvote 0
If you are calling the Excel subroutine in Word, then I'd set this variable "sheet num" as a passing variable.

Another hard way to force the issue, is to have the Excel subroutine write the value into a cell, and then when you run your stuff in word, just reference the value in the cell.
 
Upvote 0

Forum statistics

Threads
1,225,322
Messages
6,184,277
Members
453,225
Latest member
adelphiaUK

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top