Solved

Word VBA SaveAs

Posted on 2012-03-22
9
860 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
ID: 37751724
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
ID: 37751752
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
ID: 37753122
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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 37753706
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
 

Author Comment

by:rsen1
ID: 37753957
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
ID: 37754043
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
ID: 37754229
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
ID: 37754470
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
ID: 37755595
Thank you
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
This article will show you how to use shortcut menus in the Access run-time environment.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

789 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