Jump to content
Sign in to follow this  
bsmith0183

Script to launch excel file

Recommended Posts

bsmith0183

Hi I am in need of some help to write a script that will eventually be converted to an EXE and launch from a CD

After the EXE will launch it will ask the user if he or she accepts the agreement or declines the agreement. If they

accept it then it will launch the excel file from the CD, which is password protected, Is there any way to get the

script to automatically enter the Excel file password? If the user selects decline then the program would close, I couldnt

attach any code because I have no Idea how or what I should attach. I dont even know where to start.,

Thanks

Share this post


Link to post
Share on other sites
water

It can be done. But from where you are now to a running script it will take some time.

_ExcelBookOpen will allow you to use a read and/or write password.

I would devide the job into the following steps:

  • Decide how the agreement GUI should look like
  • create the GUI with an accept and decline button
  • Decide when the user accepts wether he should enter the password for the excel file or wether you want to store it somewere
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
bsmith0183

It can be done. But from where you are now to a running script it will take some time.

_ExcelBookOpen will allow you to use a read and/or write password.

I would devide the job into the following steps:

  • Decide how the agreement GUI should look like
  • create the GUI with an accept and decline button
  • Decide when the user accepts wether he should enter the password for the excel file or wether you want to store it somewere

I have the front end already created using Autoplay Media Studio It has the Accept and Decline Radio Buttons, However I just do not know how to write the code, to be able

to launch the Excel file from the CD and then enter the password so the user does not have to. Autoit has the function to covert the script to an EXE but I am not

even sure how I would even make the GUI with the accept and decline buttons, I would rather do it all in autoit if I could. Any Ideas?

Share this post


Link to post
Share on other sites
water

To create a GUI you could use "Koda". It's available from within SciTe by pressing Alt+m or unter Tools -> Koda (Form Designer).

Example for a GUI:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Excel.au3>

Global $sLicenseText =  "This is your License Text Line 1" & @CRLF & _
                        "This is your License Text Line 2" & @CRLF & _
                        "This is your License Text Line 3"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("User License Agreement", 633, 454, 265, 118)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 617, 401, BitOr($ES_READONLY,$WS_VSCROLL,$WS_HSCROLL))
GUICtrlSetData(-1, $sLicenseText)
$Accept = GUICtrlCreateButton("Accept", 8, 416, 129, 25, 0)
$Decline = GUICtrlCreateButton("Decline", 488, 416, 137, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Decline 
            MsgBox(0,"","Decline selected")
            Exit
        Case $Accept
            MsgBox(0,"","Accept selected")
            ExitLoop
     EndSwitch
WEnd

; Accept Button has been pressed
GUIDelete($Form1)
$oExcel = _ExcelBookOpen("C:\temp\test.xls",1,False,"ReadPassword","WritePassword")
If @error = 1 Then
    MsgBox(0, "Error!", "Unable to Create the Excel Object!")
    Exit
ElseIf @error = 2 Then
    MsgBox(0, "Error!", "File does not exist!")
    Exit
EndIf
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
bsmith0183

To create a GUI you could use "Koda". It's available from within SciTe by pressing Alt+m or unter Tools -> Koda (Form Designer).

Example for a GUI:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Excel.au3>

Global $sLicenseText =  "This is your License Text Line 1" & @CRLF & _
                        "This is your License Text Line 2" & @CRLF & _
                        "This is your License Text Line 3"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("User License Agreement", 633, 454, 265, 118)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 617, 401, BitOr($ES_READONLY,$WS_VSCROLL,$WS_HSCROLL))
GUICtrlSetData(-1, $sLicenseText)
$Accept = GUICtrlCreateButton("Accept", 8, 416, 129, 25, 0)
$Decline = GUICtrlCreateButton("Decline", 488, 416, 137, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Decline 
            MsgBox(0,"","Decline selected")
            Exit
        Case $Accept
            MsgBox(0,"","Accept selected")
            ExitLoop
     EndSwitch
WEnd

; Accept Button has been pressed
GUIDelete($Form1)
$oExcel = _ExcelBookOpen("C:\temp\test.xls",1,False,"ReadPassword","WritePassword")
If @error = 1 Then
    MsgBox(0, "Error!", "Unable to Create the Excel Object!")
    Exit
ElseIf @error = 2 Then
    MsgBox(0, "Error!", "File does not exist!")
    Exit
EndIf

Hey this works great and would be what we need however I do not know where in the code to put the password for the excel file.

Also I dont know how to make it so that it does not copy anything to the hard drive I need it to access an excel file off of the CD.

and I cannot copy it to the HD at all. Is this script then able to be converted into an EXE?

So I think we are almost there Thank you so much for what you have done for me so far.

Share this post


Link to post
Share on other sites
bsmith0183

Hey this works great and would be what we need however I do not know where in the code to put the password for the excel file.

Also I dont know how to make it so that it does not copy anything to the hard drive I need it to access an excel file off of the CD.

and I cannot copy it to the HD at all. Is this script then able to be converted into an EXE?

So I think we are almost there Thank you so much for what you have done for me so far.

Thanks for all your help but still no luck here is the error i am getting

Posted Image

Share this post


Link to post
Share on other sites
water

Hi bsmith0183,

Ad password:

What kind of password do you need? The Read Password to open the Excel file or the Write Password to save changes? Does the user need read or write access to the Excel file?

Ad EXE file:

Any AutoIt script can be converted to an EXE an be run from a CD. But be aware that the EXE file is only your script+the interpreter a bit encrypted and compiled into an EXE. There are tools on the internet to decompile your script an get the password.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
bsmith0183

Hi bsmith0183,

Ad password:

What kind of password do you need? The Read Password to open the Excel file or the Write Password to save changes? Does the user need read or write access to the Excel file?

Ad EXE file:

Any AutoIt script can be converted to an EXE an be run from a CD. But be aware that the EXE file is only your script+the interpreter a bit encrypted and compiled into an EXE. There are tools on the internet to decompile your script an get the password.

Hey

Thanks for getting back to me the Excel file has a password on it when you open the excel file it asks you for a password to open the document it would be the read password i guess. It does not prompt you to enter the password to save at least I dont think so anyways. The user is going to have to be able to save a copy of the excel file to their desktop so i am not sure yet on the password to save I will check and see if it asks me for it if it modify the spreadsheet at all.

thanks

thanks

Share this post


Link to post
Share on other sites
water

After having read your last post I would change the code as follows. The Excel workbook is opened readonly (parameter 3=True) so it hopefully doesn't need to write any temp files. Replace the "ReadPassword" with your password and give it a try.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Excel.au3>

Global $sLicenseText =  "This is your License Text Line 1" & @CRLF & _
                        "This is your License Text Line 2" & @CRLF & _
                        "This is your License Text Line 3"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("User License Agreement", 633, 454, 265, 118)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 617, 401, BitOr($ES_READONLY,$WS_VSCROLL,$WS_HSCROLL))
GUICtrlSetData(-1, $sLicenseText)
$Accept = GUICtrlCreateButton("Accept", 8, 416, 129, 25, 0)
$Decline = GUICtrlCreateButton("Decline", 488, 416, 137, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Decline 
            MsgBox(0,"","Decline selected")
            Exit
        Case $Accept
            MsgBox(0,"","Accept selected")
            ExitLoop
     EndSwitch
WEnd

; Accept Button has been pressed
GUIDelete($Form1)
; Open the Excel Workbook readonly and provide a read password
$oExcel = _ExcelBookOpen("C:\temp\test.xls",1,True,"ReadPassword")
If @error = 1 Then
    MsgBox(0, "Error!", "Unable to Create the Excel Object!")
    Exit
ElseIf @error = 2 Then
    MsgBox(0, "Error!", "File does not exist!")
    Exit
EndIf

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
bsmith0183

Hey some more little issues I have to work out is that I was unaware that I would need script to be able to copy the protected excel file to the hard drive in a temp folder and then open that file that it copied just because I found that if you save as after the excel doc is opened it keeps the password on the new saved excel doc meaning that if they wanted to change anything they would not be able to open the newly saved excel file. This is a problem however if they need to fix the excel doc or if they need to make changes then they would run the CD again and then it would look at the temp file first if its there it would open the existing file which would be the one that they had modified providing that they did not change the name of the excel file when they saved it. IF the file is not there anymore then it would just copy the original from the CD and the user would have to reenter all of there info. I know this is probably pretty confusing. The whole idea here is that the password on the excel file is so they cannot open the excel file with out running from the disc and so that they cannot distribute the excel file because they do not know the password, I am not worried if they try and figure out the password by somehow opening the exe to see the code, I would also like to have another window where i could write some text telling them to not change the name of the excel file after they entered there data so that if they would need to re enter anything the disc would open the modified excel doc from the temp folder.

I Thank you in advance for everything

I wish I knew how to write code better than I do.

Thanks

Share this post


Link to post
Share on other sites
bsmith0183

Hey wanted to let you know that I put all of the info in the code with the password and it opened great!

Thank you so much for what we have so far if we can get some of the stuff above accomplished I think that we will just

about have things wrapped up. I am very thankful for all of your help

thanks again Water!

Share this post


Link to post
Share on other sites
water

Ok, now it starts to get a bit complicated. I try to understand what you need so we can make the best code to suit your needs.

... I was unaware that I would need script to be able to copy the protected excel file to the hard drive in a temp folder and then open that file ...

You can open the Excel file from any location. "C:\temp\..." is just my example because I was testing my code. YOu can open it from the CD as well.

If you want to allow your users to change the Excel file why do you want to set a password? Store the Excel file without password on the CD. Let the users change the file and store it on C:\temp. The script can check on startup wether there is a version of the Excel file on C:\temp and open this file otherwise open the file from the CD.

If the user changes the filename or lcoation then it's his fault.

Just my 2 cents.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
bsmith0183

Ok, now it starts to get a bit complicated. I try to understand what you need so we can make the best code to suit your needs.

You can open the Excel file from any location. "C:\temp\..." is just my example because I was testing my code. YOu can open it from the CD as well.

If you want to allow your users to change the Excel file why do you want to set a password? Store the Excel file without password on the CD. Let the users change the file and store it on C:\temp. The script can check on startup wether there is a version of the Excel file on C:\temp and open this file otherwise open the file from the CD.

If the user changes the filename or lcoation then it's his fault.

Just my 2 cents.

ok here is the reason for the password, there is data on the real excel file that is going on the disc that the customer needs that file to not be able to be opened by double clicking it, it needs to only open by the front end exe/script which knows the password, I know this is a weird request and we have never had to do this for anyone before, We need the customer not to be able to just open the excel file when ever they want to, we need them just to be able to open it by going through the accept decline page and enter some text then save it to the temp directory overwriting the one that the exe/script copied there and opened for the user. If they try and browse to the CD and double click on the Excel file it would prompt them for the password which they would not know, if they try and browse to the folder where the Script/exe copied the excel file to and tried to double click on that file they would be prompted for a password which they would not know. If they try and open the file that they just modified and saved it also retains the original password so that is perfect all we need is that excel file whether it be the original one on the disc or the one that it copied to the hard drive and modified not to open with out running the CD. This is why we would need to copy the protected one to a temp folder then it would launch that file and they could make there modifications and then they would save it using the same file name so if they had to make any changes they could by running the cd again.

thanks

Share this post


Link to post
Share on other sites
water

OK, I changed the script a little bit. It checks for a local copy of the Excel file. If it exists this local copy is opened. If the local copy doesn't exist the copy from the CD is copied to the local disk and opened.

Do you want the user to be able to open the the local copy without the CD (and the compiled script on it)? If yes, the compiled script has to be copied to the local disk as well.

You have to modify the two variables $sLocalFile and $sCDFile.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Excel.au3>

Global $sLicenseText =     "This is your License Text Line 1" & @CRLF & _
                        "This is your License Text Line 2" & @CRLF & _
                        "This is your License Text Line 3"
Global $sLocalFile = "C:\temp\Test.xls"
Global $sCDFile       = "Test.xls"    

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("User License Agreement", 633, 454, 265, 118)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 617, 401, BitOr($ES_READONLY,$WS_VSCROLL,$WS_HSCROLL))
GUICtrlSetData(-1, $sLicenseText)
$Accept = GUICtrlCreateButton("Accept", 8, 416, 129, 25, 0)
$Decline = GUICtrlCreateButton("Decline", 488, 416, 137, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Decline 
            MsgBox(0,"","Decline selected")
            Exit
        Case $Accept
            MsgBox(0,"","Accept selected")
            ExitLoop
     EndSwitch
WEnd

; Accept Button has been pressed
GUIDelete($Form1)
; Check if there is a local copy of the file. 
;   yes: open it. 
;   no:  copy the file from the CD to the local disk and open it
If Not FileExists($sLocalFile) Then 
    If FileCopy($sCDFile,$sLocalFile,8) = 0 Then
        MsgBox(0, "Error!", "Unable to create the local copy of " & $sCDFile)
        Exit
    EndIf
EndIf
$oExcel = _ExcelBookOpen($sLocalFile,1,False,"ReadPassword")
If @error = 1 Then
    MsgBox(16, "Error!", "Unable to Create the Excel Object!")
    Exit
ElseIf @error = 2 Then
    MsgBox(16, "Error!", $sLocalFile & " does not exist!")
    Exit
EndIf

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
bsmith0183

OK, I changed the script a little bit. It checks for a local copy of the Excel file. If it exists this local copy is opened. If the local copy doesn't exist the copy from the CD is copied to the local disk and opened.

Do you want the user to be able to open the the local copy without the CD (and the compiled script on it)? If yes, the compiled script has to be copied to the local disk as well.

You have to modify the two variables $sLocalFile and $sCDFile.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Excel.au3>

Global $sLicenseText =     "This is your License Text Line 1" & @CRLF & _
                        "This is your License Text Line 2" & @CRLF & _
                        "This is your License Text Line 3"
Global $sLocalFile = "C:\temp\Test.xls"
Global $sCDFile       = "Test.xls"    

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("User License Agreement", 633, 454, 265, 118)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 617, 401, BitOr($ES_READONLY,$WS_VSCROLL,$WS_HSCROLL))
GUICtrlSetData(-1, $sLicenseText)
$Accept = GUICtrlCreateButton("Accept", 8, 416, 129, 25, 0)
$Decline = GUICtrlCreateButton("Decline", 488, 416, 137, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Decline 
            MsgBox(0,"","Decline selected")
            Exit
        Case $Accept
            MsgBox(0,"","Accept selected")
            ExitLoop
     EndSwitch
WEnd

; Accept Button has been pressed
GUIDelete($Form1)
; Check if there is a local copy of the file. 
;   yes: open it. 
;   no:  copy the file from the CD to the local disk and open it
If Not FileExists($sLocalFile) Then 
    If FileCopy($sCDFile,$sLocalFile,8) = 0 Then
        MsgBox(0, "Error!", "Unable to create the local copy of " & $sCDFile)
        Exit
    EndIf
EndIf
$oExcel = _ExcelBookOpen($sLocalFile,1,False,"ReadPassword")
If @error = 1 Then
    MsgBox(16, "Error!", "Unable to Create the Excel Object!")
    Exit
ElseIf @error = 2 Then
    MsgBox(16, "Error!", $sLocalFile & " does not exist!")
    Exit
EndIf

Hi Water

Hey I am supposed to change all the localFile and CdFiles to book1.xls which is the name of my excel doc. Do I keep the $ signs and the (s) there? Do I need to tell the code where

to put the tempfile or is that already in the code I dont see any paths in the code so thats why I am wondering.

Thanks

Share this post


Link to post
Share on other sites
water

Hi,

yes you have to change the two variables $sLocalFile and $sCDFile. $sLocalFile contains the full path and filename, $sCDFile only the filename as I assume it is copied from the drive/path were the exe is beeing run from. So in your case you would set $sLocalFile = "C:\temp\book1.xls" and $sCDFile = "book1.xls".

A $ sign denotes a variable, the "s" is just an AutoIt convention of saying: "This is a variable holding a string". So you have to keep the $ but you can change the rest of the variable name to your liking.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
bsmith0183

Hi,

yes you have to change the two variables $sLocalFile and $sCDFile. $sLocalFile contains the full path and filename, $sCDFile only the filename as I assume it is copied from the drive/path were the exe is beeing run from. So in your case you would set $sLocalFile = "C:\temp\book1.xls" and $sCDFile = "book1.xls".

A $ sign denotes a variable, the "s" is just an AutoIt convention of saying: "This is a variable holding a string". So you have to keep the $ but you can change the rest of the variable name to your liking.

Hi Water

Here is my code what am I doing wrong I get error trying to compile the project?

#include <ButtonConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#include <Excel.au3>

Global $sLicenseText = "This is your License Text Line 1" & @CRLF & _

"This is your License Text Line 2" & @CRLF & _

"This is your License Text Line 3"

Global $sLocalFile = "C:\temp\Test.xls"

Global $sCDFile = "Test.xls"

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("User License Agreement", 633, 454, 265, 118)

$Edit1 = GUICtrlCreateEdit("", 8, 8, 617, 401, BitOr($ES_READONLY,$WS_VSCROLL,$WS_HSCROLL))

GUICtrlSetData(-1, $sLicenseText)

$Accept = GUICtrlCreateButton("Accept", 8, 416, 129, 25, 0)

$Decline = GUICtrlCreateButton("Decline", 488, 416, 137, 25, 0)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE, $Decline

MsgBox(0,"","Decline selected")

Exit

Case $Accept

MsgBox(0,"","Accept selected")

ExitLoop

EndSwitch

WEnd

; Accept Button has been pressed

GUIDelete($Form1)

; Check if there is a local copy of the file.

; yes: open it.

; no: copy the file from the CD to the local disk and open it

If Not FileExists($book1.xls) Then

If FileCopy($book1.xls,$book1.xls,8) = 0 Then

MsgBox(0, "Error!", "Unable to create the local copy of " & $book1.xls)

Exit

EndIf

EndIf

$oExcel = _ExcelBookOpen($book1.xls,1,true,"test")

If @error = 1 Then

MsgBox(16, "Error!", "Unable to Create the Excel Object!")

Exit

ElseIf @error = 2 Then

MsgBox(16, "Error!", $book1.xls & " does not exist!")

Exit

EndIf

Should I change the Local File one to $c:\temp\book1.xls ???

Thanks

Share this post


Link to post
Share on other sites
water

You shouldn't change the OCCURANCE of the variable in the source code but the VALUE of the variable. So please take my original source code and only change the two lines at the beginning:

Global $sLocalFile = "C:\temp\Test.xls"
Global $sCDFile    = "Test.xls"

so after the change they sould read:

Global $sLocalFile = "C:\temp\book1.xls"
Global $sCDFile    = "book1.xls"
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
bsmith0183

You shouldn't change the OCCURANCE of the variable in the source code but the VALUE of the variable. So please take my original source code and only change the two lines at the beginning:

Global $sLocalFile = "C:\temp\Test.xls"
Global $sCDFile    = "Test.xls"

so after the change they sould read:

Global $sLocalFile = "C:\temp\book1.xls"
Global $sCDFile    = "book1.xls"

Hi Water

Hey I feel like an idiot for not seeing that. I just entered in the changes and it works great, However i just found out that there are other things that this script/exe needs to do, How or what

code would I need to not have a gui or any kind of accept or decline box. Basically what I need now is just the script to open the protected excel file with out showing anything on the screen kind of what we have just with out the accept or decline menu.

Thanks for your help

Share this post


Link to post
Share on other sites
water

Taken my code from posting #14 I stripped off the unnecessary lines:

#include <Excel.au3>

Global $sLocalFile = "C:\temp\book1.xls"
Global $sCDFile       = "book1.xls"    

; Check if there is a local copy of the file. 
;   yes: open it. 
;   no:  copy the file from the CD to the local disk and open it
If Not FileExists($sLocalFile) Then 
    If FileCopy($sCDFile,$sLocalFile,8) = 0 Then
        MsgBox(0, "Error!", "Unable to create the local copy of " & $sCDFile)
        Exit
    EndIf
EndIf
$oExcel = _ExcelBookOpen($sLocalFile,1,False,"ReadPassword")
If @error = 1 Then
    MsgBox(16, "Error!", "Unable to Create the Excel Object!")
    Exit
ElseIf @error = 2 Then
    MsgBox(16, "Error!", $sLocalFile & " does not exist!")
    Exit
EndIf
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×