I am trying to open a workbook from a userform in outlook and have this code in the command button on the userform
and in a regular modulePrivate Sub CommandButton1_Click() ' Workbooks.Open FileName:="C:\DownLoads\Cover Pages Test.xls" Call OpenExcelFile("C:\DownLoads\Cover Pages Test.xls") End Sub
When I click the command button this gets highlited as an errorPublic 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
the error beingDim oWB As Workbook
"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.
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.
Thank you very much, it works just great
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks