Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login

POZE MRRRR'S FORUM (VIEW ONLY)

Nu sunteti logat.
Nou pe simpatie:
Juliaa pe Simpatie
Femeie
22 ani
Galati
cauta Barbat
27 - 80 ani
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides / [VBS] Check if Excel file is Open Moderat de TRaP, TonyTzu
Autor
Mesaj Pagini: 1
TRaP
Moderator

Inregistrat: acum 6 ani
Postari: 732
To test, paste the following code in Notepad and save as .vbs

Change the name of your Excel file accordingly.
Mind the extension - I noticed that uppercase (.XLSX) or lowercase (.xlsx) extension makes a difference - code won't work the same for both.



'Note: your file might have lowercase extension, you will have to change it to lowercase, otherwise it won't work
ExcelFileName = "export.XLSX"
If objXL Is Nothing Then
    MsgBox "There is no Excel file open.", vbOkOnly, "Excel not found!"
    Exit Sub
End If

On Error Resume Next
Set xl = GetObject(, "Excel.Application")  'attach to running Excel instance

If Err Then
  If Err.Number = 429 Then
    WScript.Echo "Excel is not running (workbook not open)."
  Else
    WScript.Echo Err.Description & " (0x" & Hex(Err.Number) & ")"
  End If
    WScript.Quit 1
End If
On Error Goto 0

Set wb = Nothing
For Each obj In xl.Workbooks
  If obj.Name = ExcelFileName Then  'use obj.FullName for full path
    Set wb = obj
    WScript.Echo "Workbook is OPEN - OK"
    Exit For
  End If
Next

If wb Is Nothing Then
  WScript.Echo "Workbook not open."
  WScript.Quit 1
End If


Source:


pus acum 2 ani
   
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2182
Added the part in color for the case when the Excel application is not open.

_______________________________________


pus acum 12 luni
   
Pagini: 1  

Mergi la