PDA

View Full Version : Solved: Changing from .DOT to .DOC



Kindly_Kaela
01-18-2007, 09:01 AM
Hello!

I have several WORD templates created that are minipulated depending on the user's choices. Currently, after my macro runs and the changes occur, the file name remains as .DOT. If the user hits save, they will replace my template (which is obviously bad).

What code would you recommend I use to ensure the users save the manipulated template as a .DOC?

Can I also change the file name so when they hit SAVE my template name doesn't appear?

And lastly, when they hit SAVE, can thier MY DOCS appear instead of my company's network drive (where the templates are stored)?

Thanks!
Kaela
:cloud9:

lucas
01-18-2007, 09:36 AM
Sounds like your users are actually opening the .dot template instead of using it as a template...

How are they accessing the file. Do they open word and go to file-New and locate your template?

Bob Phillips
01-18-2007, 09:44 AM
You should store those .dot files in a network location, update all the users copy of word to point at that location (Tools>Options>File Locations>Workgroup templates), and then get the users to open it via File>New.

Kindly_Kaela
01-18-2007, 09:57 AM
The way it's set up is the user answers multiple questions via user_forms. Thier answers determine which template opens. After the template opens, several changes are made (ie. Find/Replace, deleting sections, inserting visio's, etc.) When the macro is complete, the document is ready for them to print and save.

Lucas, no. They are accessing the template through my VBA program after they make several radial button and textbox choices .

Bob, the files are all stored on the network. However, I do not want the users to open them from File>New. I want the VBA program to open them, and then manipulate them.

Here's the part of the code that I'm using to open the template. I did not include the code that makes several changes (as mentioned in my 'ie' above). When the user goes to save the finished product, I want the file name to change and Save_AS location to be My Docs (if possible).


Private Sub CB_Next_Click()

' Determines which proposal template to open
If ProdChoice = "ManagedHosting" Then
ProdFileName = "INVMHS"
ElseIf ProdChoice = "ManagedDesktop" Then
ProdFileName = "INVMITS"
ElseIf ProdChoice = "iHosting" Then
ProdFileName = "iHosting"
ElseIf ProdChoice = "iLPAR" Then
ProdFileName = "iLPAR"
ElseIf ProdChioce = "iRemote" Then
ProdFileName = "iRemote"
ElseIf ProdChoice = "Implementation" Then
ProdFileName = "HostMigration"
Else
MsgBox "No Product Specified"
End If

' This code opens the desired template
ChangeFileOpenDirectory "X:\ProposalGenerator\Templates\"
Documents.Open FileName:=ProdFileName + ".dot", ConfirmConversions:=False, ReadOnly _
:=False, AddToRecentFiles:=True, PasswordDocument:="", PasswordTemplate _
:="", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="" _
, Format:=wdOpenFormatAuto, XMLTransform:=""

End Sub

Bob Phillips
01-18-2007, 10:24 AM
Instead of using

Documents.Open

use

Documents.OpenAsDocument

this opens a template as a document, thereby presrving your .dot file.

BTW, I would make the .dot files read-only, protect them.

Kindly_Kaela
01-18-2007, 10:25 AM
I inserted that....but not working. Please advise.


ChangeFileOpenDirectory "X:\ProposalGenerator\Templates\"
Documents.OpenAsDocument FileName:=ProdFileName + ".dot", ConfirmConversions:=False, ReadOnly _
:=False, AddToRecentFiles:=True, PasswordDocument:="", PasswordTemplate _
:="", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="" _
, Format:=wdOpenFormatAuto, XMLTransform:=""


I prematurely hit SOLVED :(

Bob Phillips
01-18-2007, 10:35 AM
Sorry, this way works



sDir = "X:\ProposalGenerator\Templates\"
Documents.Add.AttachedTemplate = sDir &ProdFileName + ".dot"

Kindly_Kaela
01-18-2007, 10:41 AM
Now it's just opening a blank document instead of the template.

lucas
01-18-2007, 10:45 AM
Documents.Add Template:= _
"F:\Documents and Settings\Main\Application Data\Microsoft\Templates\RFI.dot" _
, NewTemplate:=False, DocumentType:=0

lucas
01-18-2007, 10:59 AM
This works for me.......
Sub a()
Dim sDir As String
Dim ProdFileName As String
sDir = "F:\Documents and Settings\Main\Application Data\Microsoft\Templates\"
ProdFileName = "RFI"
Documents.Add Template:= _
sDir & ProdFileName + ".dot", NewTemplate:=False, DocumentType:=0
End Sub

Kindly_Kaela
01-18-2007, 11:11 AM
Lucas, very nice! Thank you!!
:mkay

lucas
01-18-2007, 11:16 AM
I hate to tell you this but I used the macro recorder to get this......but your welcome.

Kindly_Kaela
01-18-2007, 11:22 AM
What's a Macro Recorder?

J/K!!

:p

lucas
01-18-2007, 11:25 AM
Ha...funny girl...it's a last ditch effort for me sometimes.:doh:

Kindly_Kaela
01-18-2007, 11:26 AM
OK, here's an add on question.

I want to change the file name to Company Name + today's date as a 6 digit number.

For example....

Microsoft_011807.doc

I'm stuck on the date part. This code works, just trying to figure out how to insert the date.



Sub SaveAsDate()

Dim CompInitials As String
CompInitials = "Microsoft"

ActiveDocument.SaveAs FileName:=CompInitials + ????, FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword:="", _
ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, _
SaveFormsData:=False, SaveAsAOCELetter:=False

End Sub

fumei
01-18-2007, 11:28 AM
1. Select Case is better than using If..ElseIf.

2. Why add extra string concatenations, when you can do it in one operation? That is, why add the ".dot" as an extra? Do it all together.

Dim sFolder As String
Dim sUseTemplate As String
sFolder = "X:\ProposalGenerator\Templates\"
Select Case ProdChoice
Case "ManagedHosting"
sUseTemplate = sFolder & "INVMHS.dot"
Case "ManagedDesktop"
sUseTemplate = sFolder & "INVMITS.dot"
Case "iHosting"
sUseTemplate = sFolder & "iHosting.dot"
Case "iLPAR"
sUseTemplate = sFolder & "iLPAR.dot"
Case "iRemote"
sUseTemplate = sFolder & "iRemote.dot"
Case "Implementation"
sUseTemplate = sFolder & "HostMigration.dot"
Else
MsgBox "No Product Specified"
End Select
Documents.Add Template:=sUseTemplate

fumei
01-18-2007, 11:34 AM
ActiveDocument.SaveAs Filename:="Microsoft_" & Format(Now, "mmddyy")

Kindly_Kaela
01-18-2007, 11:39 AM
I got an error on the Else statement.


Else
MsgBox "No Product Specified"


By the way, thank you! I really appreciate you helping me learn on things I didn't even ask about. Awesome!!

fumei
01-18-2007, 11:42 AM
Sorry, that should be:

Case Else

!!!!

Kindly_Kaela
01-18-2007, 11:51 AM
Sweet! Date works! Case Else works! Kaela happpppy!

:dance: