Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 955
  • Last Modified:

Word VBA SaveAs

Hi, please see attached.

In Word I have "my company" in the top left corner is there a vba code that will save the file as "my company" in a file in "c:\master".

Thank you
save-as.doc
0
rsen1
Asked:
rsen1
  • 4
  • 4
1 Solution
 
GrahamSkanCommented:
It is possible to write code that will do exactly that. It isn't clear what you would do with it, but this does exactly what you ask.

ActiveDocument.SaveAs "c:\master\my company.doc"
0
 
Chris BottomleyCommented:
LOoks to me as though it's something like:

Dim rng As Range

    Set rng = ThisDocument.Paragraphs(1).Range
    rng.MoveEnd wdCharacter, -1
    ThisDocument.SaveAs "c:\master\" & rng.Text & ".doc"

Open in new window


Chris
0
 
rsen1Author Commented:
Thank you for your responses, as I read your responses I see I did not ask my question very well. The response from Chris is the direction I was seeking. I don't know much about Word, I generally work with excel.

However, please see attached, I can't get the code to work. I placed your code in a button, which it seems I have very little control as to where it is placed on the document and also it is in a macro.
save-as.doc
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
GrahamSkanCommented:
That's because the first paragraph includes a string of spaces and an ActiveX control, which makes an illegal file name. This is the quick way to get the text at the beginning of the paragraph, but we don't know if this rule would apply to all versions of this template/document

Private Sub sav_Click()
    Dim rng As Range
    Dim strName As String
    Set rng = ActiveDocument.Paragraphs.First.Range
    strName = Split(rng.Text, "  ")(0)
    'rng.MoveEnd wdCharacter, -1
    ActiveDocument.SaveAs "c:\master\" & Trim(strName) & ".doc"
End Sub

Open in new window

0
 
rsen1Author Commented:
Thank you that works in the macro, but not the button. Is it best not to use buttons in Word?
0
 
GrahamSkanCommented:
I think that it is best to not use buttons on the Word document. They don't really look good on the printed output.

In Word 2003, you can create buttons to go on to a toolbar, either a pre-existing one, or one of your own.

I'm not in 2003 at the moment, but the idea is that you put the macro in a VBA code module in a template. It is best to start by putting it in the Normal template. Once it is there you can use the Word Tools/Customize dialogue. Choose 'macros' in the left hand list, locate your macro and drag it to a toolbar. Dismiss the Customise dialogue, and you should be able to run the macro by clicking on the new button
0
 
rsen1Author Commented:
Thank you again for your response, what do you mean by, "Dismiss the Customise dialogue, and you should be able to run the macro by clicking on the new button"
0
 
GrahamSkanCommented:
By 'dismiss', I meant click 'OK',  'Done' or the equivalent. As I suggested, I didn't have my 2003 system running, so I couldn't be more explicit.
0
 
rsen1Author Commented:
Thank you
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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