Solved

Word VBA SaveAs

Posted on 2012-03-22
9
845 Views
Last Modified: 2012-08-14
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
Comment
Question by:rsen1
  • 4
  • 4
9 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
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
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
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
 

Author Comment

by:rsen1
Comment Utility
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
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:rsen1
Comment Utility
Thank you that works in the macro, but not the button. Is it best not to use buttons in Word?
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
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
 

Author Comment

by:rsen1
Comment Utility
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
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
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
 

Author Comment

by:rsen1
Comment Utility
Thank you
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now