+ Reply to Thread
Results 1 to 3 of 3

Thread: Open excel workbook from Outlook UserForm

  1. #1
    Registered User
    Join Date
    01-09-2011
    Location
    Gabrieola
    MS-Off Ver
    2003,2007
    Posts
    28

    Open excel workbook from Outlook UserForm

    I am trying to open a workbook from a userform in outlook and have this code in the command button on the userform
    Private Sub CommandButton1_Click()
       ' Workbooks.Open FileName:="C:\DownLoads\Cover Pages Test.xls"
       Call OpenExcelFile("C:\DownLoads\Cover Pages Test.xls")
    End Sub
    and in a regular module
    Public Function OpenExcelFile(ByVal File_Name As String) As Boolean
    Dim oWB As Workbook
       On Error Resume Next
           Set oWB = Workbooks.Open(File_Name)
       On Error GoTo 0
       OpenExcelFile = Not oWB Is Nothing
    End Sub
    When I click the command button this gets highlited as an error
    Dim oWB As Workbook
    the error being
    "User Defined Type Not defined"

    How can I open the workbook in an Outlook Userform and then get textbox1 to display in cell B6 in that workbook
    Last edited by NewGuy OnBlock; 01-13-2011 at 08:24 PM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Cochrane,Alberta
    MS-Off Ver
    XL 2003,2007,2010
    Posts
    6,843

    Outlook Userform,Open excel workbook,Outlook Userform Textbox to excel

    In the Outlook VBA Editor, type createobjects, select the word and hit F1 to get help on it.

    When I did this I got this help screen.

    Working with the help code you should be able to figure out something that works for you.

    Try this
    Private Sub CommandButton1_Click()
    
        Dim xlApp As Object, Sht As Object
    
        Set xlApp = CreateObject("Excel.Application")
        xlApp.Application.Visible = True
        xlApp.Workbooks.Open "C:\DownLoads\Cover Pages Test.xls"
    
        'xlApp.Application.Quit
    
        Set Sht = xlApp.Worksheets(1)
    
        Sht.Range("B6").Value = TextBox1
    
        Set xlApp = Nothing
    
        Unload Me
    
    End Sub
    Last edited by davesexcel; 01-15-2011 at 01:34 PM.

  3. #3
    Registered User
    Join Date
    01-09-2011
    Location
    Gabrieola
    MS-Off Ver
    2003,2007
    Posts
    28

    Re: Open excel workbook from Outlook UserForm

    Thank you very much, it works just great

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0