hexagon logo

Checking if the excel is open - here I go again.

Some of our operators do not close the excel before running another part which causes excel to not save data. The data is dent to excel via a script.

How can i check if the excel is open and if so close it?

Thanks
Parents


  • I didn't say it doesn't work, just that i don't know what to do with it.
    I understand the principal behind what you're saying, but i'm not a coder and i don't know how to code it. I had a course in C++ many years ago and that is the extant of my coding knowledge.
    What I've done so far was done by copy/paste, looking at examples and trial and error.



    I did one module of Visual Basic at Uni years ago. The rest was self taught / copy pasted / modified etc etc.

    Debugging will help you figure it out.

    FileName = Part.partname & " " & strVariable & " " & reasonVar & ".xlsm"
    MsgBox(FileName)
    Workbook(FileName).Close 'Close results workbook

    If the file name is being generated correctly then you may need to loop through the open workbooks checking for a match, before you try close it



    (This is psudocode - i.e. It shows tha basic structure but the exact syntax etc might not be right.)

    i.e.

    for i = 1 to workbooks.count

    if workbooks(i).name = FileName then
    workbook(i).close
    end if
    next i
Reply


  • I didn't say it doesn't work, just that i don't know what to do with it.
    I understand the principal behind what you're saying, but i'm not a coder and i don't know how to code it. I had a course in C++ many years ago and that is the extant of my coding knowledge.
    What I've done so far was done by copy/paste, looking at examples and trial and error.



    I did one module of Visual Basic at Uni years ago. The rest was self taught / copy pasted / modified etc etc.

    Debugging will help you figure it out.

    FileName = Part.partname & " " & strVariable & " " & reasonVar & ".xlsm"
    MsgBox(FileName)
    Workbook(FileName).Close 'Close results workbook

    If the file name is being generated correctly then you may need to loop through the open workbooks checking for a match, before you try close it



    (This is psudocode - i.e. It shows tha basic structure but the exact syntax etc might not be right.)

    i.e.

    for i = 1 to workbooks.count

    if workbooks(i).name = FileName then
    workbook(i).close
    end if
    next i
Children
No Data