![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Extract names of running applications. (Excel) Hi If a sheet is open while the vb script is writing new data, I got something like this: Microsoft Excel: Can't access 'R.XLS' Is there a way to check for Excel is running, so I can let the script write a message, "PLEASE CLOSE ANY EXCEL SHEET before you continue the script!" How to check is running? Benny Pedersen, PS: Below is three functions for your code archives. ![]() 1: getF. Use it to get a file or folder... 2: ShowFile. Use it to open a folder (intended for CScript, not WScript). 3: KillApp. Kill any app you want to quit. set fso= createObject("scripting.fileSystemObject") set wso= createObject("wScript.shell") function getF(byVal sFSpec, byVal sWhat) sWhat= lCase(sWhat) sFSpec= wso.expandEnvironmentStrings(sFSpec) sFSpec= fso.getAbsolutePathName(sFSpec) on error resume next if sWhat = "file" then getF= fso.getFile(sFSpec) else if sWhat="parent" then sFSpec= fso.getParentFolderName(sFSpec) ' sFSpec= fso.buildPath(sFSpec,"\") getF= fso.buildPath(fso.getFolder(sFSpec),"\") end if if err then getF= sFSpec: err.clear ' end function sub ShowFile(sFile) dim sPath:sPath= getF(sFile, "parent") wScript.echo "--> Open folder, """ & sPath & """" if fso.fileExists(sFile) then dim oFile: set oFile= fso.getFile(sFile) wScript.echo vbCrLf & vbTab & oFile.type & " """ & fso._ getFileName(sFile) & """, " & oFile.size & " byte."& vbCrLf &_ vbTab & "Created: "& oFile.dateCreated & vbCrLf &_ vbTab & "Modified: "& oFile.dateLastModified & vbCrLf set oFile= nothing wso.run "explorer.exe /select,"""& sFile & """" else wso.run "explorer.exe """& sPath & """" end if wScript.echo "--> Folder is open." & vbCrLf end sub sub KillApp(byVal app) dim KillExe: KillExe= "%windir%\system32\atskill.exe" if fso.fileExists(getF(KillExe,"file")) then wso.run """" & KillExe & """ """ & app & """", 7, true wso.run""""& KillExe &""" """& KillExe & """", 7, false else msgBox "File not found, ""TSKILL.EXE""" & vbLf _ & "Tips: Search KILL on your system.", 4096 end if end sub |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Extract names of running applications. (Excel) "Benny Pedersen" <b.pedersen@xxxxxx> wrote in message news:b34d1356-a5c4-43b9-b4fe-07c14bfae04e@xxxxxx Quote: > Hi > > If a sheet is open while the vb script is writing new data, > > I got something like this: Microsoft Excel: Can't access 'R.XLS' > > Is there a way to check for Excel is running, so I can let the > script write a message, "PLEASE CLOSE ANY EXCEL SHEET before you > continue the script!" > > How to check is running? > > Benny Pedersen, > > PS: Below is three functions for your code archives. ![]() > > 1: getF. Use it to get a file or folder... > 2: ShowFile. Use it to open a folder (intended for CScript, not > WScript). > 3: KillApp. Kill any app you want to quit. > > set fso= createObject("scripting.fileSystemObject") > set wso= createObject("wScript.shell") > > function getF(byVal sFSpec, byVal sWhat) > sWhat= lCase(sWhat) > sFSpec= wso.expandEnvironmentStrings(sFSpec) > sFSpec= fso.getAbsolutePathName(sFSpec) > on error resume next > if sWhat = "file" then > getF= fso.getFile(sFSpec) > else > if sWhat="parent" then sFSpec= fso.getParentFolderName(sFSpec) ' > sFSpec= fso.buildPath(sFSpec,"\") > getF= fso.buildPath(fso.getFolder(sFSpec),"\") > end if > if err then getF= sFSpec: err.clear ' > end function > > sub ShowFile(sFile) > dim sPath:sPath= getF(sFile, "parent") > wScript.echo "--> Open folder, """ & sPath & """" > if fso.fileExists(sFile) then > dim oFile: set oFile= fso.getFile(sFile) > wScript.echo vbCrLf & vbTab & oFile.type & " """ & fso._ > getFileName(sFile) & """, " & oFile.size & " byte."& vbCrLf &_ > vbTab & "Created: "& oFile.dateCreated & vbCrLf &_ > vbTab & "Modified: "& oFile.dateLastModified & vbCrLf > set oFile= nothing > wso.run "explorer.exe /select,"""& sFile & """" > else wso.run "explorer.exe """& sPath & """" > end if > wScript.echo "--> Folder is open." & vbCrLf > end sub > > sub KillApp(byVal app) > dim KillExe: KillExe= "%windir%\system32\atskill.exe" > if fso.fileExists(getF(KillExe,"file")) then > wso.run """" & KillExe & """ """ & app & """", 7, true > wso.run""""& KillExe &""" """& KillExe & """", 7, false > else msgBox "File not found, ""TSKILL.EXE""" & vbLf _ > & "Tips: Search KILL on your system.", 4096 > end if > end sub script that exist in the universe", you appear to suffer from a pronounced lack imagination when it comes to performing everyday scripting tasks. C'mon, do a bit of your own thinking before posting and use the countless clues you received to your previous posts! |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Extract names of running applications. (Excel) On Jan 12, 11:26*pm, "Monitor" <nos...@xxxxxx> wrote: Quote: > "Benny Pedersen" <b.peder...@xxxxxx> wrote in message > > news:b34d1356-a5c4-43b9-b4fe-07c14bfae04e@xxxxxx > > > > > Quote: > > Hi Quote: > > If a sheet is open while the vb script is writing new data, Quote: > > I got something like this: Microsoft Excel: Can't access 'R.XLS' Quote: > > Is there a way to check for Excel is running, so I can let the > > script write a message, "PLEASE CLOSE ANY EXCEL SHEET before you > > continue the script!" Quote: > > How to check is running? Quote: > > Benny Pedersen, Quote: > > PS: Below is three functions for your code archives. ![]() Quote: > > 1: getF. Use it to get a file or folder... > > 2: ShowFile. Use it to open a folder (intended for CScript, not > > WScript). > > 3: KillApp. Kill any app you want to quit. Quote: > > set fso= createObject("scripting.fileSystemObject") > > set wso= createObject("wScript.shell") Quote: > > function getF(byVal sFSpec, byVal sWhat) > > * sWhat= lCase(sWhat) > > * sFSpec= wso.expandEnvironmentStrings(sFSpec) > > * sFSpec= fso.getAbsolutePathName(sFSpec) > > * on error resume next > > * if sWhat = "file" then > > * * getF= fso.getFile(sFSpec) > > * else > > * * if sWhat="parent" then sFSpec= fso.getParentFolderName(sFSpec) ' > > * * sFSpec= fso.buildPath(sFSpec,"\") > > * * getF= fso.buildPath(fso.getFolder(sFSpec),"\") > > * end if > > * if err then getF= sFSpec: err.clear ' > > end function Quote: > > sub ShowFile(sFile) > > * dim sPath:sPath= getF(sFile, "parent") > > * wScript.echo "--> Open folder, """ & sPath & """" > > * if fso.fileExists(sFile) then > > * * dim oFile: set oFile= fso.getFile(sFile) > > * * wScript.echo vbCrLf & vbTab & oFile.type & " """ & fso._ > > * * getFileName(sFile) & """, " & oFile.size & " byte."& vbCrLf &_ > > * * vbTab & "Created: *"& oFile.dateCreated & vbCrLf &_ > > * * vbTab & "Modified: "& oFile.dateLastModified & vbCrLf > > * * set oFile= nothing > > * * wso.run "explorer.exe /select,"""& sFile & """" > > * else wso.run "explorer.exe """& sPath & """" > > * end if > > * wScript.echo "--> Folder is open." & vbCrLf > > end sub Quote: > > sub KillApp(byVal app) > > * dim KillExe: KillExe= "%windir%\system32\atskill.exe" > > * if fso.fileExists(getF(KillExe,"file")) then > > * * wso.run """" & KillExe & """ """ & app & """", 7, true > > * * wso.run""""& KillExe &""" """& KillExe & """", 7, false > > * else msgBox "File not found, ""TSKILL.EXE""" & vbLf _ > > * * & "Tips: Search KILL on your system.", 4096 > > * end if > > end sub > For someone who previously boasted "writting [sic] the fastest sorting > script that exist in the universe", you appear to suffer from a pronounced > lack imagination when it comes to performing everyday scripting tasks. > C'mon, do a bit of your own thinking before posting and use the countless > clues you received to your previous posts!- Hide quoted text - > > - Show quoted text - About my previous sorting script: I'm still working on it, but since it became faster each time I worked on it, it maybe was not the fastest sorting script in the univerce. Anyhow, since I haven't published the faster version, I maybe did learned something. In other words: I won't show the sorting script now, tomorrow nither... ![]() Benny |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| running Excel Macro in in specified Excel files in spe | PowerShell | |||
| Excel / .Net: Extract a given Range into Picture or X(HT)ML? | .NET General | |||
| Programs/Applications running | Vista performance & maintenance | |||
| iis 7.0 - applications running under dot net framework 1.1 | Vista installation & setup | |||