Change file type from template to document in VBA

riggsd

Board Regular
Joined
Jan 29, 2003
Messages
143
How do I change a file type from .dotx to .docx in VBA? I can save it with the .docx format but it's actually still saving as a template.

Currently, I have the following code:

'set doc name to contract number, document number, task order, and CDRL item number
docName = (CStr(frmName.Contract_Number.Column(1))) & "-" & txtDOTO & _
"-" & (CStr(frmName.CDRL_Number.Column(1))) & "_" & (CStr(frmName.Document_Number)) & _
"_" & (CStr(frmName.Document_Revision)) & "_Disposition" & ".docx"
fullName = CurrentProject.Path & "" & docName 'set fullName to path plus docName

wrdDoc.SaveAs fileName:=fullName

I know there's a way to set the file type when saving it but so far, the stuff I've found just confuses me more.

Thanks,
Dar
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
How do I change a file type from .dotx to .docx in VBA? I can save it with the .docx format but it's actually still saving as a template.

Currently, I have the following code:

'set doc name to contract number, document number, task order, and CDRL item number
docName = (CStr(frmName.Contract_Number.Column(1))) & "-" & txtDOTO & _
"-" & (CStr(frmName.CDRL_Number.Column(1))) & "_" & (CStr(frmName.Document_Number)) & _
"_" & (CStr(frmName.Document_Revision)) & "_Disposition" & ".docx"
fullName = CurrentProject.Path & "" & docName 'set fullName to path plus docName

wrdDoc.SaveAs fileName:=fullName

I know there's a way to set the file type when saving it but so far, the stuff I've found just confuses me more.

Thanks,
Dar

Dar,

If you are using Word automation to open the template and save it then you may be opening it it incorrectly.

You don't normally open the template file. Instead, with a template (.dotx) you normally create a new word document based on the template. This will automatically convert it to a normally document. then you save as normally for any new document.

Something this to load the template into a new document:

Code:
wrdDoc.Documents.Add Template:="path to template file"
then save the new document



See:Documents.Add Method (Word)
 
Upvote 0
I tried this:

tPath = (TrailingSlash(CurrentProject.Path) & "Disposition_Letter_Template_Approved.dotx")
wrdDoc.Documents.Add Template:=tPath

and it opened a Word file but it was blank, it didn't have the text/bookmarks in it from my template.

I'm using VBA to open the file and insert text into various bookmark locations.
 
Last edited:
Upvote 0
I tried this:

tPath = (TrailingSlash(CurrentProject.Path) & "Disposition_Letter_Template_Approved.dotx")
wrdDoc.Documents.Add Template:=tPath

and it opened a Word file but it was blank, it didn't have the text/bookmarks in it from my template.

I'm using VBA to open the file and insert text into various bookmark locations.

It would be helpful to see the rest of the code. That way we can test it.
 
Upvote 0

Forum statistics

Threads
1,223,796
Messages
6,174,657
Members
452,575
Latest member
Fstick546

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top