Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 699
Default HELP: Trying to a word template with name from userform at a diff

Hi All,

I want to export details from excel userform to a word template and save it
at a different file. So basically once the user clicks the Export to word
button this should happen:

-Opens up a dialog window(to select the word template)
- User Selects the word template (I have a specific word template designed)
- the template is then "SAVED AS" a seperate word file at a specific
location(mentioned in code below)

But what is happening is, When user clicks the button and selects the
template, the data is exported to that template, and its not saved in a
different word file at the specified location in the code.

Private Sub Export_To_Word_Click()

Dim wdApp As Object
Dim doc As Object
Dim fdialog As FileDialog
Dim pathAndFile As String
Dim filePath As String
Dim shortName As String

On Error Resume Next
Set wdApp = GetObject(, "Word.Application")

If Err.Number < 0 Then
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0

wdApp.Visible = True

Set fdialog = wdApp.FileDialog(msoFileDialogFilePicker)

With fdialog
.AllowMultiSelect = False
.Filters.Clear
.InitialFileName = filePath & "\*.dotx*"

If .Show Then
pathAndFile = .SelectedItems(1)
shortName = Right(pathAndFile, _
Len(pathAndFile) - InStrRev(pathAndFile, "\"))
Else
MsgBox "User cancelled. Did not select a file"
GoTo Pastcode
End If
End With

Set fdialog = Nothing

Set doc = wdApp.Documents.Open(pathAndFile)

On Error Resume Next
With doc
..variables("Address").Value = Me.Property_Address.Value
..variables("City").Value = Me.City.Value
..variables("State").Value = Me.State.Value
..variables("Zipcode").Value = Me.Zip_Code.Value
..Fields.Update
End With

doc.SaveAs FileName:=filePath

filePath = "C:\My Documents" _
& "Property Details" & " - " & Me.File_Number.Value & ".doc"

Pastcode:

wdApp.Quit
Set doc = Nothing
Set wdApp = Nothing

End Sub


Thanks in advance

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I link between a Word template and an Excel template Josh Excel Discussion (Misc queries) 0 April 1st 08 12:36 AM
Fastest way to store each word in a cell in a diff variable J@Y Excel Programming 1 July 25th 07 02:56 PM
Macro to find a word and copy all rows with this word to diff ws Chas Excel Programming 3 April 27th 07 11:16 PM
Access from add_in userform to main template userform.... Ajit Excel Programming 1 November 18th 04 05:15 PM


All times are GMT +1. The time now is 06:42 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"