PDA

View Full Version : Solved: SaveAs using bookmarks



Spratt_Cary
09-08-2007, 06:12 PM
I have been searching the KB for coding that performs the SaveAs function using bookmarks for the naming convention. I have a spreadsheet that opens a work template with bookmarks.
Thanks in advance.:hi:

mdmackillop
09-09-2007, 01:30 AM
You need to explain further

Spratt_Cary
09-09-2007, 05:07 AM
OK, thanks mdmackillop. When the end user finishes input into the userform, the coding in the spreadsheet opens the word template and shuts down the Userform/spreadsheet. I am using "names" in the spreadsheet and using "bookmarks" in the word template. As soon as document 1 opens I would like to do a "SaveAs" immediately using 3 of the bookmarks. example
1829A=form, Add new personnel=description, 2007-09-09 7:58=date, So I would like for the SaveAs to look like the following.
1829A_Add new Personnel_2007-09-09 7:58.doc
I hope this helps make sense of my needs and if this has the ability to be coded. I searched the KB for hours but could not find anything and I am finding that word is very different than XL for me that is. thanks in advance.

mdmackillop
09-09-2007, 07:12 AM
Are you infilling the bookmarks from Excel or are you wanting to use data that exists in the template already.

mdmackillop
09-09-2007, 08:10 AM
Option Explicit

Sub Macro1()
'Requires reference to Microsoft Word xx.x Object Library
Dim objWord As New Word.Application
Dim wdDoc As Word.Document
Dim wdTmp As String, MyStr As String
Dim arr(), a
Dim MyPath As String

MyPath = "C:\Templates\Testing.dot" '<==Amend to suit

Set wdDoc = objWord.Documents.Add(Template:=MyPath, NewTemplate:=False, _
DocumentType:=0)

arr = Array("Form", "Description", "Date")
For Each a In arr
wdTmp = wdDoc.Bookmarks(a).Range.Text
wdTmp = Left(wdTmp, Len(wdTmp) - 1)
MyStr = MyStr & wdTmp & "_"
Next
MyStr = Left(MyStr, Len(MyStr) - 1)
wdDoc.SaveAs "C:\" & MyStr & ".doc"
objWord.Quit
End Sub

Norie
09-09-2007, 09:36 AM
What exactly is going into the bookmarks?

Is it values from the userform?

If so why not use those instead of the bookmarks for the save as?

Spratt_Cary
09-09-2007, 01:09 PM
thanks mdmackillop,
I pasted the above code in my command button 1 and it error out on wdTmp = Left(wdTmp, Len(wdTmp) - 1). I am not sure why or how to correct it.

Norie, yes row A3 to J3 has the information that is used for the bookmarks and this changes everytime a user completes the form.

I have tried to attach without success.

Norie
09-09-2007, 01:19 PM
You've kind of lost me now.

First you mention bookmarks, then a userform and now a range (Excel?).:)

Spratt_Cary
09-09-2007, 01:29 PM
Lorie, I am attaching the spreadsheet and then I will attach the template. I am sorry for being so vague, newbie is the only thing that I can say. thanks

Spratt_Cary
09-09-2007, 01:46 PM
Template will not attach.

fumei
09-09-2007, 01:52 PM
ZIP them.

Spratt_Cary
09-09-2007, 02:11 PM
Here's the template

Spratt_Cary
09-09-2007, 02:12 PM
Here's the spreadsheet

Spratt_Cary
09-09-2007, 02:24 PM
Sorry, just realized that Password on code = ivrs