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 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
    Tutuapp 9apps Showbox
    workbook(i).close
    end if

    next i


    no i think he did not generate the file correctly
Reply



  • 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
    Tutuapp 9apps Showbox
    workbook(i).close
    end if

    next i


    no i think he did not generate the file correctly
Children
No Data