+ Reply to Thread
Results 1 to 8 of 8

How to open a different word document when selection in excel drop down box changes (VBA)

  1. #1
    Registered User
    Join Date
    09-10-2014
    Location
    Austin
    MS-Off Ver
    2010
    Posts
    14

    How to open a different word document when selection in excel drop down box changes (VBA)

    Hello.

    I am very new to VBA and am trying to develop a code that opens up a different word document when the selection in the excel drop down box changes. I know one option is to do an if/then statement, but I am unsure of the syntax.

    Any help would be appreciated!

    Here is my code for opening up a template in Word:

    Set WrdApp = CreateObject("Word.Application")
    WrdApp.Visible = True
    Set WrdDoc = WrdApp.Documents.Open("C:\Users\" & UserID & "\Desktop\Quantien Evaluation with Certus and WiBox Template.docx")

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: How to open a different word document when selection in excel drop down box changes (V

    Is the "drop down" box a datavalidation list? If so what cell is it in?

    You want it opened after every change? Or only if changed to a certain value?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Registered User
    Join Date
    09-10-2014
    Location
    Austin
    MS-Off Ver
    2010
    Posts
    14

    Re: How to open a different word document when selection in excel drop down box changes (V

    Yes, it's a datavalidation list. It's in cell A2. I want a different word document to open if a different selection from the dropdown box is chosen.

    For example, there are 5 selections to make in the drop down box. For each selection, I would like my program to open a different word document template.

    Basically, the entire program is this: Open up word template, change variables with find/replace, save word document, save as pdf, open up outlook new email and attach pdf.

  4. #4
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: How to open a different word document when selection in excel drop down box changes (V

    Will it be a form letter for Outlook? If that is the case couldn't the template be a sheet in your workbook?

    Is it necessary to use Word?

  5. #5
    Registered User
    Join Date
    09-10-2014
    Location
    Austin
    MS-Off Ver
    2010
    Posts
    14

    Re: How to open a different word document when selection in excel drop down box changes (V

    Yes it is necessary to use word, the templates have already been created. They are template contracts (there are about 15 templates I am trying to do this for- which is why I am wanting to try the drop down box in excel - less bulky). Instead of creating the contracts manually using a template, I am trying to create a program that automates them with a few bits of information into some excel cells (like customer name, city, state, etc.), then opens up a new email with this automated contract attached.

    The template could be a sheet in the workbook, but other people would be using this tool and I wouldn't want to cause any confusion. I would rather everything be in the macro and all they would have to do was enter in some information click a button and everything is done.

  6. #6
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: How to open a different word document when selection in excel drop down box changes (V

    This is pretty simple and doesn't include any error trapping.

    Might need an example to work with if it gets any more involved.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    09-10-2014
    Location
    Austin
    MS-Off Ver
    2010
    Posts
    14

    Re: How to open a different word document when selection in excel drop down box changes (V

    Solus,

    I have tried this code and it worked in a test run but when I incorproated it into my program I get a 424 run time error.

    Dim UserId As String

    UserId = Sheets("QuantienEvaluations").Range("M5").Value2


    Set WrdApp = CreateObject("Word.Application")
    WrdApp.Visible = True

    If Sheets("QuantienEvaluations").Range("A2") = "QuantienAerisOnly" Then Set WrdDoc = WrdApp.Documents.Open("C:\Users\" & UserId & "\Desktop\Quantien With Aries Only.docx")
    If Sheets("QuantienEvaluations").Range("A2") = "QuantienAerisCertus" Then Set WrdDoc = WrdApp.Documents.Open("C:\Users\" & UserId & "\Desktop\Quantien With Aeris and Certus.docx")
    If Sheets("QuantienEvaluations").Range("A2") = "QuantienAdditionalWiBoxAerisOnly" Then Set WrdDoc = WrdApp.Documents.Open("C:\Users\" & UserId & "\Desktop\Quantien With Aeris and Additional Wibox.docx")
    If Sheets("QuantienEvaluations").Range("A2") = "QuantienAdditionalWiBoxAerisCertus" Then Set WrdDoc = WrdApp.Documents.Open("C:\Users\" & UserId & "\Desktop\Quantien With Aeris and Certus and Additional WiBox.docx")



    WrdDoc.SaveAs2 Filename:= _
    "C:\Users\" & UserId & "\Desktop\ " & CustomerName & " " & City & " " & State & " " & CustomerNumber & " " & "Quantien Evaluation Agreement" & " " & Month(Now()) & "." & Day(Now()) & "." & Year(Now()) & ".docx" _
    , FileFormat:=13, LockComments:=False, _
    Password:="", AddToRecentFiles:=True, WritePassword:="", _
    ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
    SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
    False, CompatibilityMode:=14

  8. #8
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: How to open a different word document when selection in excel drop down box changes (V

    On what line does it error?

    Realistically to trouble shoot this you will probably have to attach your workbookas an example.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. open excel source document in background when i open word document
    By hootiebsc in forum Word Programming / VBA / Macros
    Replies: 5
    Last Post: 03-22-2013, 07:50 PM
  2. Open Word Document from excel VBA
    By z0rpia in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-19-2009, 07:16 PM
  3. Open A Word Document from Excel
    By roadkill in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-04-2005, 06:20 PM
  4. [SOLVED] what happens if I open an excel document in word?
    By Emily in forum Excel General
    Replies: 3
    Last Post: 04-02-2005, 06:09 AM
  5. [SOLVED] Open Word Document from Excel
    By Will Brown in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-07-2005, 10:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1