Jump to content

Recommended Posts

Posted

Hi everyone,I'm trying to open a txt file that is saved in the script path but somehow I can't get it to work :P It's not opening it

#include <GuiConstants.au3>
#include <IE.au3>
#include <File.au3>
#include <ExcelCOM_UDF.au3> 
#include <Array.au3>
#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <Constants.au3>

$ScriptHome = @ScriptDir & "\"
$file = FileOpen($ScriptHome & "DNCSAVideoGood.txt", 1)

does anyone have any ideas please?

Posted (edited)

@ToyBoi....FileOpen() is used to get the file "handle". To read the file, look in help file for FileRead(). To launch the file use ShellExecute("myfile.txt", "", @ScriptDir, "edit")

Edited by DjDeep00
Posted

thanks, the purpose of opening the file is to copy everything from it and paste it into a new excel macro, here is my modified code

#include <GuiConstants.au3>

#include <IE.au3>

#include <File.au3>

#include <ExcelCOM_UDF.au3>

#include <Array.au3>

#include <GUIComboBox.au3>

#include <GuiConstantsEx.au3>

#include <Constants.au3>

$ScriptHome = @ScriptDir & "\" & "DNCSAVideoGood.txt"
$oExcel = _ExcelBookNew(1)
_ExcelSheetAddNew($oExcel, "NA")

:records a new macro and then go to vba editor to edit it
send("{ALT}")
send("t""m""r")
send("VideoGoodDNCSA")
send("{ENTER}")
send("{ALT}")
send("t""m""r")
send("{ALT}""t""m""m")
sleep(50)
send("!e ")
;($ScriptHome & "DNCSAVideoGood")

$file = FileOpen($ScriptHome, 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in 1 character at a time until the EOF is reached
While 1
    $chars = FileRead($file)
    If @error = -1 Then ExitLoop
   
Wend

FileClose($file)
send($chars)

I had autoit show me the variable $char in a msgbox and i was exactly the same as my text file, but when i close the file for it to paste into vba, it wouldn't, do you have any ideas?

Posted

Hi everyone,I'm trying to open a txt file that is saved in the script path but somehow I can't get it to work :P It's not opening it

#include <GuiConstants.au3>
#include <IE.au3>
#include <File.au3>
#include <ExcelCOM_UDF.au3> 
#include <Array.au3>
#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <Constants.au3>

$ScriptHome = @ScriptDir & "\"
$file = FileOpen($ScriptHome & "DNCSAVideoGood.txt", 1)

does anyone have any ideas please?

Check out this thread started by Spiff59.

Should give you a good idea on how to import the module directly using Excel's COM interface

http://www.autoitscript.com/forum/index.php?showtopic=77545

Posted

Check out this thread started by Spiff59.

Should give you a good idea on how to import the module directly using Excel's COM interface

http://www.autoitscript.com/forum/index.php?showtopic=77545

thanks for the reply, I actually did use his way of importing at first and I got the same error that he was getting

$ScriptHome = @ScriptDir & "\" & "DNCSAVideoGood.txt"
$oExcel = _ExcelBookNew(1)
_ExcelSheetAddNew($oExcel, "NA")
    
    $oModules = $oExcel.ActiveWorkbook.VBProject.VBComponents
       $oModules.Import($ScriptHome)

The above was my code, I was confused when he talked about COM+ error handler, and I didn't know what to do about that, perhaps if I had the COM+ error handler the code would have worked?

also when i used $TargetFile = "C:\test.xls"

$oExcel = ObjCreate("Excel.Application")

i got an error saying there was a problem with the excel udf at about line 2200 something

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
×
×
  • Create New...