Need simple.

Crysaline

New Member
Joined
Apr 17, 2014
Messages
2
Okay, I need something extremely simple because I am a self-taught VBA macro user. I have a macro that opens 15 Excel spreadsheets one of which is for reference only and the others I may or may not alter. Then I have another macro that saves and closes each of these spreadsheets. I need to add a Word document to these 2 macros. Open it in the first one and close without saving it in the second one. I will not be changing the document. It is open for reference only. I think the "Dim"s and "Set"s are just a bit out of my league right now. - Crysaline
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try these:
Code:
Sub Open_Word()
    Dim WordApp As Object
    Set WordApp = CreateObject("Word.Application")
    WordApp.documents.Open Filename:="C:\Users\RickXL\Documents\Test.docx", ReadOnly:=True
    WordApp.Visible = True
    WordApp.Activate
End Sub

Sub Close_Word()
    Dim WordDoc As Object
    Set WordDoc = GetObject("C:\Users\RickXL\Documents\Test.docx")
    WordDoc.Application.Quit
End Sub

The names of the macros are not significant, you could use any.
The Word document is opened in ReadOnly mode.
The filename has to be the same in both macros so that Excel can find which instance of Word it should be closing.
Change the file names to be the one you want to use.

How I think of Dims and Sets ...
Dim is like specifying a blank form. It has a name, a shape or layout and some named boxes to be filled in. It lets the program know the shape of the data it is going to be using.
Set is when you fill the form in.
 
Upvote 0
In a word "Awesome". Added to existing macros for one button operation from ribbon and worked like a charm.
I love the opportunity to learn new things and will add this to my repertoire. I have gone from a person that used Lotus 1-2-3 20 years ago to teaching myself Excel Macros that turn a days worth of work into less than an hour. Still looking for a simple solution to getting rid of named ranges on every individual sheet leaving only the "workbook" scope. I found one but it is a little too intimidating for me.
Again, Thanks.
Crysaline
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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