#179460 - 2007-08-17 11:58 PM
Re: Script Request
[Re: Templar]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
You can always navigate to wellknown places in the workbook, like the first empty cell in column A. The macro recorder is very helpfull in revealing the code
;Script Options If Not @LOGONMODE Break On Else Break Off EndIf Dim $RC $RC = SetOption("Explicit", "On") $RC = SetOption("NoMacrosInStrings", "On") $RC = SetOption("NoVarsInStrings", "On") If @SCRIPTEXE = "KIX32.EXE" $RC = SetOption("WrapAtEOL", "On") EndIf
;Declare variables DIM $objExcel
;Initialize variables ;Create the Excel object, check if succeeded, else quit $objExcel = CreateObject("Excel.Application") If @ERROR Exit @ERROR EndIf
;Code ;Show Excel $objExcel.Visible = -1 ;Open workbook with read-only password $RC = $objExcel.Workbooks.Open("C:\test\Book1.xls",,,,"test") ;Goto cell A1 (Ctrl-Home) $RC = $objExcel.Range("A1").Select ;Goto first empty cell (End, Arrow Down) $RC = $objExcel.Selection.End(xlDown).Select ;Get $RC |
|
|
Top
|
|
|
|
#179461 - 2007-08-18 01:11 AM
Re: Script Request
[Re: Witto]
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Ah ok - I see that password now. I was looking in "Protection" and "Protect Sheet" and "Protect Workbook", not in Options ... anyways, here's a modified script for that password protection ...
Break On
$= SetOption("WrapAtEol", "On")
$= SetExcelValue("c:\sheet.xls", "tuesday", "B5", "123", "abc123")
? @SERROR
Exit 1
Function SetExcelValue($path, $sheet, $range, $value, $password)
Dim $Excel
Dim $WorkBook
Dim $WorkSheet
$Excel = CreateObject("Excel.Application")
If @ERROR = 0
$Excel.DisplayAlerts = 0
$WorkBook = $Excel.WorkBooks.Open($path,,,,$password)
If @ERROR = 0
$WorkSheet = $WorkBook.Sheets.Item($sheet)
If @ERROR = 0
$WorkSheet.Range($range).Value = $value
$= $WorkBook.Save()
$WorkSheet = 0
Endif
$WorkBook = 0
Endif
$Excel.Quit
$Excel = 0
Endif
Exit @ERROR
EndFunction
|
|
Top
|
|
|
|
#179474 - 2007-08-20 01:40 PM
Re: Script Request
[Re: Lonkero]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
|
er - no.. that's not the issue..
The Ops staff had admin rights with an alternate account. If you log in with admin rights, the uptime tool uses the registry to find the boot time and such similar records. Accurate enough, but if you are not an admin - as the Ops team was when they were logged into their workstations - the tool "appears" to work, and does so by looking for the boot record in the event log. Not finding the boot record, it takes the "oldest" record in the log as the boot time. I guess the team the wrote the tool never had to dump and archive their event logs!
Doc - if my staff was using admin accounts for normal logins, I'd have a real issue with that! The problem with the tool is that it appears to respond normally, except for a short message at the end - not where you'd be focusing your attention when doing an uptime check. You need to either use RunAs, or log directly into the server with your admin account to get accurate data.
Just something to be aware of if you choose to use this tool, that's all. For the record, I use this tool extensively, but only when I'm logged in as an admin.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#179478 - 2007-08-20 06:52 PM
Re: Script Request
[Re: Glenn Barnas]
|
Templar
Fresh Scripter
Registered: 2002-04-11
Posts: 41
Loc: Cincinnati
|
I tried the last code adn it still does not enter in the password when the prompt comes up. It does update the file when I enter in the password. How does Excel get a password passed to it?
|
|
Top
|
|
|
|
#179479 - 2007-08-20 08:23 PM
Re: Script Request
[Re: Templar]
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
I dont know - works for me. If I manually start the spread-sheet I get a little tiny dialog box (like this) asking me for the password:
--------------------------
'sheet.xls' is protected
Password: [ ]
--------------------------
If I run the script above and change $password to be the correct password - no prompt and the spreadsheet just updates itself.
Can anybody else try (make sure to have a sheet called "Tuesday" in your workbook and set the password from Tools->Options.
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
1 registered
(Allen)
and 1198 anonymous users online.
|
|
|