Solved

Word VBA SaveAs

Posted on 2012-03-22
9
868 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Outlook Free & Paid Tools
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

749 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