• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

Help with VBA

Hi All,

I'm a newbie to programming and need help with a fairly simple VBA project for work. Starting in MS Excel, I'm trying to program a Macro to (1) open an existing file in MS Word, (2) enter some text from MS Excel into MS Word, and (3) Save the MS Word document with a dynamically generated file name.

For some reason, I can not get the MS Word document to save to a new file name. Would appreciate your help in figuring out what's wrong with this code!!

(Note: the variables dt and docName are created in an earlier part of the code and I'm confident they're working correctly. I'm just limiting the below code sample to the messed up code)

Dim wrdApp As Word.Application
Set wrdApp = CreateObject("Word.Application")
Dim wrdDoc As Word.Document
Set wrdDoc = wrdApp.Documents.Open("C:\Desktop\Quote_Template.doc")

With wrdApp
    .Selection.Goto What:=wdGoToBookmark, Name:="Date"
    .Selection.TypeText (dt)
End With

wrdDoc.SaveAs ("C:\Desktop\" & docName)

End Sub
  • 2
1 Solution
Does docName include the extension?
DC1983Author Commented:
Macro, thank you for your response. Yes, the docName has a ".doc" at the end of the variable.
Did you get an error message ?

did you do a display of "C:\Desktop\" & docName immediate before the saveas ?
DC1983Author Commented:
Wow! Just tried it and the error was in that piece of code. Thanks so much for the help!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now