Solved

Word VBA SaveAs

Posted on 2012-03-22
9
897 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
 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Suggested Courses

624 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