#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.16.1 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here ;********************** ;TESTING SCRIPT - Cannot get the Excel csv file to open when a variable is used (rather than the "string - - -" itself) ;************************ #include #include #include #include #include #include #include "UIAWrappers.au3" #include ;_DebugSetup() AutoItSetOption("MustDeclareVars", 1) #cs ;GET THE DOWNLOADED PORTFOLIO CSV FILENAME - This seems to be working, just commented out for using a fixed filename for testing Dim $dnlddir = "C:\Users\dgend\Downloads" FileChangeDir($dnlddir) Dim $sFileName Dim $hSearch = FileFindFirstFile("*.csv") Consolewrite("$hSearch " & $hSearch & @CRLF) ; Check if the search was successful, if not display a message and return False. If $hSearch = -1 Then MsgBox($MB_SYSTEMMODAL, "", "Error: No files/directories matched the search pattern.") ;Return False EndIf MsgBox(0,"hSearch",$hSearch) $sFileName = FileFindNextFile($hSearch) #ce ;USE A CONSTANT FILENAME FOR TESTING: Local $sFilename $sFilename = "growthinvestor-portfolio-2023-03-04.csv" MsgBox(0, "FileName = ", $sFilename) ;CREATE THE FULL PATHNAME FOR "Filename" ;"C:\Users\dgend\Downloads\growthinvestor-portfolio-2023-03-04.csv" Assign("scsvPath", '"' & "C:\Users\dgend\Downloads\" & $sFilename & '"') Local $CSVpath = Eval("scsvPath") ;This string in the variable does not open the csv file MsgBox(0, "csvPath= ", $CSVpath) Local $scsvPathString $scsvPathString = StringStripWS($CSVpath, $STR_STRIPALL) ;This string in the variable does not open the csv file ;$scsvPathString = "C:\Users\dgend\Downloads\growthinvestor-portfolio-2023-03-04.csv" ;When I use the string itself, the file opens! MsgBox(0, "csvPathString= ", $scsvPathString) ; Create application object Dim $oAppl = _Excel_Open() If @error Then Exit MsgBox(16, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_BookOpen($oAppl, $scsvPathString) ;Does not open file ;_Excel_BookOpen($oAppl,"C:\Users\dgend\Downloads\growthinvestor-portfolio-2023-03-04.csv") ;Does open the file ;All the strings displayed in the MsgBox's look correct 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 - Shame on you!") Exit EndIf MsgBox(0, "status", "Opened ?") Exit