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 did one module of Visual Basic at Uni years ago. The rest was self taught / copy pasted / modified etc et

    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


    Thanks NB, I'll try this today.

    Quick question. What compiler are you using?
    I installed Visual Studio Code, but it looks very different than what i remember from back in the day.
Reply



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

    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


    Thanks NB, I'll try this today.

    Quick question. What compiler are you using?
    I installed Visual Studio Code, but it looks very different than what i remember from back in the day.
Children
No Data