Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-17-2008, 07:56 AM
jroleon jroleon is offline
Registered User
 
Join Date: Aug 2008
Posts: 2
How to check if a specific excel workbook is already open

Hi, I have an script to backup my routers, the IP`s are in a excel workbook and the script gets information (Ios,crc`s) of the routers and places it in the same Excel workbook, I`m going to share my script to my partners but some times they don`t close the work book and they can`t save the information, So I want to determine if Excel file is open before tu run the scipt and if it`s open to show a msgbox to ask to close it, is it posible ?

I have tested this but only check the excel aplication not works with a specific file.

# $language = "VBScript"
# $interface = "1.0"
Sub Main
Dim wb
On Error Resume Next
Set wb = Nothing
Set wb = GetObject(, "Excel.Application")
msgbox Err

If wb Is Nothing Then
MsgBox "close"
else
MsgBox "open"

end if
On Error GoTo 0
End Sub

And this, show me a Compiler Error

# $language = "VBScript"
# $interface = "1.0"

Sub Main

On Error Resume Next
Dim intFile

intFile = FreeFile()
Open "C:\backups\routers.xls" For Input Lock Read As intFile
Close intFile

If err <> 0 Then
msgbox "open"
End If

end sub

Any help would be appreciated.
Thanks,
jroleon
Reply With Quote
  #2  
Old 09-17-2008, 10:46 AM
kbarnette kbarnette is offline
VanDyke Technical Support
 
Join Date: Aug 2007
Posts: 587
Hi jroleon,

There isn't an easy way to determine if an Excel spreadsheet is already open. Fortunately I was able to perform a quick search and locate a forum where general scripting solutions like these have already been made available.

This forum can be found here.

Is this information helpful?
Reply With Quote
  #3  
Old 09-18-2008, 08:19 AM
jroleon jroleon is offline
Registered User
 
Join Date: Aug 2008
Posts: 2
This works, I just need to put not common name to my Excel spreadsheet

Sub Main
set objShell = CreateObject("Wscript.Shell")
Set objWord = CreateObject("Word.Application")
Set colTasks = objWord.Tasks
u = 0
For Each objTask in colTasks
strName = LCase(objTask.Name)

If Instr(strName,"routers_script")
u = 1
End If
Next
If u = 0 Then
msgbox "close"
End If
If u = 1 Then
msgbox "open"
End If
objWord.Quit
end sub


Thanks for youl help
jroleon
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 03:17 PM.