Saving a word doc in Excel VBA

alexransome

Board Regular
Joined
Jun 10, 2011
Messages
192
Hi,

So currently I have a sheet which has cells linked to a table in a word document. I have some VBA which will open that word doc at some point and then the table will refresh. Currently I'm having to then save the file manually, but I'd like to save the doc using VBA and save it with a file name from a cell.

Can that be done?

Thanks.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try this

VBA Code:
  Dim objWord As Object
  Set objWord = CreateObject("Word.Application")
  '
  'your code
  '
  'here put path \ sheet.cell
  objWord.ActiveDocument.SaveAs ThisWorkbook.Path & "\" & Sheets("Sheet1").Range("D2")
 
Upvote 0
Hi,

I got confused by what you were suggesting ...

Would it be possible to add the line required at the end of this ...

VBA Code:
    Set wordapp = CreateObject("word.Application")
    wordapp.Documents.Open "C:\Users\name\Desktop\VAF.docx"
    wordapp.Visible = True

The idea still being that the word document is opened, updates the field links and then saves it self, the name would need to be "VAF-*****" and the * would be a cell (E16) reference.
 
Upvote 0
I managed to cobble this together ...
VBA Code:
'Auto save
    wordapp.ActiveDocument.SaveAs "C:\Users\name\Desktop\VAF-" & Sheets("eMail").Range("E16")

And it works ... Very surprised at me.
 
Upvote 0
In the future, try to put your code, because we don't know how you declared your application. I just put an example:
Set objWord = CreateObject ("Word.Application")

You had to update your code "wordapp" with my example.

I see that in the end you made it.

I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,962
Messages
6,122,482
Members
449,088
Latest member
Melvetica

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