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

0
Utf
11/17/2009 5:25:22 AM
excel.programming 6508 articles. 2 followers. Follow

0 Replies
903 Views

Similar Articles

[PageSpeed] 2

Reply:

Similar Artilces:

Query Help
Ok, I am trying to write a query that basically calculates the same data as the HQ Report labeled "Detailed Sales Report". The only number I want is the final total sales run between two dates. This information is going on a custom report I am creating for my CFO. The query I have so far is this: SELECT sum(transactionentry.price) AS price FROM TransactionEntry INNER JOIN [Transaction] WITH(NOLOCK) ON TransactionEntry.TransactionNumber = [Transaction].TransactionNumber AND TransactionEntry.StoreID = [Transaction].StoreID INNER JOIN Batch WITH(NOLOCK) ON [Transaction].BatchNu...

newbie help with instances
I'm working on a program in MSVC++6.0. The program will eventually control a mobile robot. Right now I can draw a grid on the screen and a circle representing the robot. I have a class that contains some variables like x-position and y-position. I can modify those variables from robotView.cpp (which the wizard created), but not from commands.cpp (commands is the form that has my buttons on it). I created an instance in robotView that allows me to access the variables. A similar instance in commands does not change the variables, and I can't access the same instance as in robotView. Whe...

Help with ShowFilter macro
I'm trying to use this ShowFilter UDF written by Tom Ogilvy (see bottom of post). It says to use... =showfilter(B2)&CHAR(SUBTOTAL(9,B3)*0+32) ....in a cell to show the criteria for Column B. For one thing, I don't understand the cells B2 and B3 business. What is supposed to be in those cells? I would like this function to appear in the cell directly above or below the Autofilter menu cell. How do I change the function if the Autofilter criteria menu is in, cell A3, for example, and I want the criteria (this function) to appear just above, in cell A2? After trying all so...

Need advice to start off a project
Hello! I have never really used Excel much but I have had an idea which could make some of the work I do a lot easier. I know Excel is powerful but I don't know the best way to approach it so can anyone out there help me? I make visits to places and record what kind of visit it was on a spreadsheet with the values in each cell being the date. At the bottom there is a summary box which shows, on each date, how many visits I made of each type. At the moment this is done manually but I am sure it can be done automatically only how? On a different sheet I would then like to have a summary of...

Help with mailing list!! If 3+ people @ 1 address, send 2, if 5+ s
So, I guess I am in need of help with an "IF THEN" statement here... I have 18k records on a sheet. I am trying to 'auto-evaluate' the database - I don't want to send 10 catalogs to 1 address if there are 10 customers. I just want to send 2 for up to 5 customers, 3 for 5+... I don't want to waste that much paper (both capital, and physically, paper). I was hoping I could simply filter down the listings, not from 10 to 1, but from 10 to 3, and from 5 to 2... Does this make sense? Any help is greatly appreciated... Thanks, ...

how do I copy several lines of word text into one excel cell?
In a word doc I need to copy several lines of text and paste them into one excel cell. I can't seem to find any help telling me how to do this (each line pastes into a different cell) You can either double click the cell or press F2 key to get into edit mode for the cell, then the text pasted would all go into the cell. -Simon "jhh" wrote: > In a word doc I need to copy several lines of text and paste them into one > excel cell. I can't seem to find any help telling me how to do this (each > line pastes into a different cell) thank you SO much Simon CC - ...

Exporting mailing list to MS Word using Mail Merge
I am having trouble using the Mail Merge fuction on MS Word 2003. I cannot import list from saved .xls file in Excell 2003. I have full customer information fileds including name, address, and city/state fields but cannot import these fields to Word to create mailing labels.Need help! Thank You Each entry in the excel file needs to be on one row. Example: A2 = lastname1, B2 = firstname1, C2 = Address1, D2 = state1 ... A3 = lastname 2, B3 = firstname2 etc etc Make sure there is no other information on that sheet (except possibly column headers) Then in Word, using the mail me...

Excel 2007 will not start.... all of a sudden.. pls help
Hi, I have Office 2007... All modules were working fine on clicking icons of word,access,excel etc. All of a sudden to day I can not start.. excel.. other programs .. starts. on starting excel. clicking Icon... I get message as follow. " This file does not have a program associated with ith it for performing this actoion. Create an association with set association control Panel. " Also when With window explorer I go in office12 folder clicking excel EXE file doe not start error message this is not win32 file. can somebody help.. or do I have to reinstall Office 2007 ...

BOB? More Craps HELP #2
Hi Bob Been spending some time on the code you sent and I think I found some errors. Can you check the code below to see what you think? I think it is now working according to the correct rules... Dim cellvalue Sub Craps() 'Excel Craps V1.3 Application.ScreenUpdating = False Range("B5:C1000").Select Selection.ClearContents Range("A4").Select Setup: Application.ScreenUpdating = True [B5] = [B2] Rollem: If (([B5] = 2) Or ([B5] = 3) Or ([B5] = 12)) Then GoTo CrapOut If (([B5] = 7) Or ([B5] = 11)) Then GoTo FirstLucky cellvalue = 0 GoTo NotWinner End NotWinner: ...

Duplication Macro & Macro crashing Word
I used this forum to get help with some Visual Basic before because I'm an absolute novice. I was given advice on a couple of Macros, one which duplicates text from another form field and one that changes the colours of cells based on a selection from a dropdown form field, but I am now having some issues with both of them. The duplication macro: Sub CopyText() With ActiveDocument .FormFields("Bookmark1").Result = .FormFields("Bookmark2").Result End With End Sub The problem I have with the macro above is when the text is copied from "...

Command Button Help
I have created a spreadsheet with multiple command buttons on them. Whenever I print or printpreview, they all move to the left. Why will they not stay in place? How can i get them to stay in place? Thanks for the help!!! http://support.microsoft.com/d´┐Żefault.aspx?kbid=838910 Controls move to the left of the worksheet in Microsoft Excel 2002 There's a link on this URL: http://support.microsoft.com/default.aspx?kbid=838910 How to obtain the hotfix This issue is fixed in the Excel 2002 post-Service Pack 3 hotfix Hotfix Package May 6, 2004. For additional information, click the ...

Named Range question #2
I have several named ranges in my spread sheet. Basically I want to vary the name used in many formulas without having to manually modify those formulas. For example: There are many range names defined, say range_one, range_two, etc. There are many cells that use range names. For example Average(name_one), sum(name_one), etc. Again I want to change the range name in these formulas without manually modifying the formulas. Any way to do this? If there are not too many, you can do a Find and Replace and they will replace the names (even in the formulas). Don wrote: > I have severa...

template in a shared workbook
When I attempt to insert a template worksheet into a shared workbook I get the error that This command is not allowed on a shared workbook. It will allow me to insert a blank worksheet into the same shared workbook. Excel 2000. My template folder is configured through WORD to be on the network drive so it does appear as an option to insert it into the workbook. Thank you for your help. ...

Help #10
I have asked for help twice and have recieved a reply twice. Both times I am unable to see the text. I am directed to click a link to read the reply. it opens a blank window. Please respond using my hotmail address OABenedict@Hotmail.com. Then I should be able to see the text. My origional question is: How do i set the default paper feed to auto when using Publisher 2007? Thank you OAB Bear wrote: > I have asked for help twice and have recieved a reply twice. Both > times I am unable to see the text. I am directed to click a link to > read the reply. it opens a blank wi...

contacts w/wrong names problem
I have a user whos contacts look really jumbled in spots. His contacts "disapear". Upon further investigation (he has 4000+ contacts) other peoples names are being put on other contacts. So bryan smith will appear twice, and john carpenter is missing, however, johns info just has brians name on it. How is this possible? Import gone wrong? Data corruption? He is "missing" several contacts, which I suspect are the same issue. Please post a coherent question that includes accurate and specific details others could understand. Include versions and precise steps t...

Convert Template to Form
How can I possibly convert an outlook tamplate to an outlook form? Thanks for your help. "template" is a type of "form" in Outlook, so it's not clear what you = want to do. Can you give us more details?=20 --=20 Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for=20 Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx =20 <ksenya.lim@gmail.com> wrote in message = news:1156945681.610123.4310@74g2...

Recovery Help, urgent!!! thank you.
Exchange 5.5 is sitting on the PDC of NT 4 domain. There are 5 hard drive in the box, and 1 of them just failed this morning. The directory service and IS service won't start, but the PDC is functioning properly. The exchange is spanned accross 5 of the disks. I also have the Directory and IS backed up with backup exec 9.1 from last night. What's survived are: \dsadata\DIR.EDB \mdbdata\*.LOG What's lost on the failed HD are: \mdbdata\PRIV.EDB \mdbdata\Pub.EDB \dsadata\*.log What kind of approch should I take to restore the IS once I installed the new HD. How can I get th...

Please Help #2
Hi, I posted a thread a couple of days back. However, never really explaie the problem very well. I work in insurance. I receive a spreadsheet every week with a list o about 500 policy holders. It contains various columns of informatio (about 10 columns). My department, however, only deals with 164 of these 500 polic holders. As a result, I was wondering if anyone knew of a macro tha could filter out these 164 policy holders from the spreadsheet an either place them on a new sheet or filter out the policy holders tha we didn't deal with. At the moment all I have is a seperate sheet A1...

frank kabel- help me.
a long back i have put a problem I had sent to you a example file (unfortunately i have missed) and you have suggested OFFSET function. I have applied this as below =OFFSET($E$35,0,(ROW(1:1)-1)*2) it is a great function for me. but now it is creating a problem. after some row (in some sheet on row 44 and in some sheet on 58) the values are displaying. PLEASE HELP ME. A EARLY REPLY IS SOLICITED. thanks in advance. s karan -- kumawat_s ------------------------------------------------------------------------ kumawat_s's Profile: http://www.excelforum.com/member.php?action=getinfo&...

NEWBIE to ACCESS help with forms
Hi, I am looking to have a form, With 1 combo boxes (telephone), and the rest text boxes. I want to be able to select a telephone number and have the other 2 boxes shows the associated firstname and last name so for example.. I have a table with 3 fields telephone first name last name Additionally IF POSSIBLE would want to be able to choose a last name, and it show the telephone and first name associated Access 2003 Thanks in advance When you create a combo box using the wizard, it gives you two options: Save the combo box selection to a field or Look up a record using the combo ...

help me please #2
hi I am trying using outlook for the first time , although I use it at workd , but there it is set up already by the admin here , I am getting this "invalid login" with reported error (0x80004005), and for the other email (0x8000ccc32) there are many fields to fill in 1-your name: when openning new email address , there is first name , last name should i enter the first name only or what? 2-user name what should i enter here suppose my emal is someone940@hotmail.com should my user name be someone940 ? 3-http mail server provider : hotmail? so please help me "mhmaid...

Splitting names from cells
My first question to the hordes of folks better equipped to answer than the people around me. I'm a policy advisor and I only use Excel and Access as they relate to research. I'm trying to figure out if there is a method for splitting first and last names from a cell where both are contained. We have a huge fleet database with thousands of operator names, but when some moron first set up the system, they put entire name (JOHN A DOE) in one cell. Is there a way I can search for the string following the final space, or some such thing, so I can separate the names? Thanks. -- Goe...

one column market word but i want this word i want right column
i want urangt ans you will need to give slighty more information if you would like some help. vaibhav wrote: >i want urangt ans -- Matt Lynn Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.aspx/excel-new/201005/1 ...

Help with a simple form
I need help with a very simple form. I have a glossary for my team defined in Excel. I want to set up a form that will let them key in the first few letters of either the acronym or the term itself and show all items in the worksheet that start with those letters. As you key more letters, it refines more. Kind of like the index function in Help. Secondly, I want to set up an input form that a user would fill out that would then save that information into a second spreadsheet (behind the look up one). Then an administrator would review those entries regularly and add the entries to...

Syntax error when using names with apostrophe
i'm getting syntax error message for this button that tries to get name (of building) with apostrophe. Any idea how to solve this? Note that i must use name with apostrophe e.g. O'neal: Private Sub Command76_Click() On Error GoTo Err_Command76_Click Dim stDocName As String Dim stLinkCriteria As String stDocName = ChrW(1506) & ChrW(1491) & ChrW(1499) & ChrW(1503) & ChrW(32) & ChrW(1508) & ChrW(1512) & ChrW(1496) & ChrW(1497) & ChrW(32) & ChrW(1502) & ChrW(1489) & ChrW(1504) & ChrW(1492) stLin...