简体   繁体   中英

Outlook VBA open excel

I am trying to open an existing excel sheet from outlook. I can see the workbook open and then it imediately closes again. I have the Excel.Application set to visible. Any ideas? Here is the code.

Function openNewForm(toDoSubject)
    MsgBox ("Called")
    Dim xlApp As Object
    Dim sourceWB As Workbook
    Dim sourceSH As Worksheet

    Set xlApp = CreateObject("Excel.Application")

    With xlApp
        .Visible = True
        .EnableEvents = False
    End With


    strFile = "C:\Users\Peter\Documents\ASI\OrderSystem\NewOrderSheet.xlsm"

    Set sourceWB = Workbooks.Open(strFile, , False, , , , , , , True)
    Set sourceSH = sourceWB.Worksheets("OrderForm")
    sourceWB.Activate
End Function

Again this code is running in outlook. I want to keep the file open once it opens.

I got it figured out. I was opening a different workbook and then closing it before I try to open the second one and that was interfering with it. To fix this I kept the excel app open and reset the workbook object to the new workbook i wanted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM