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: Export data to word template and save it as a seperate file

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
Export user inputs to a template and save it as a different file sam Excel Programming 1 October 8th 09 07:02 PM
Export cell data to a template in Word mike Excel Programming 1 August 3rd 07 09:20 AM
Automate Export from Form Template to Seperate Table QuestDave Excel Discussion (Misc queries) 0 August 31st 05 05:25 PM
Convert, export, or save Word as an image file (jpg, gif, png, etc quartz[_2_] Excel Programming 1 April 20th 05 04:20 PM
export excel data to a word template using a macro Ross1 Excel Programming 1 March 25th 05 04:31 AM


All times are GMT +1. The time now is 01:22 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"