I
Ian G
I know this post is really old and I doubt I will get a reply.. Can you post your working script for excel spreadsheets? This is exactly what I have been looking for. Good work!
Phil Hibbs wrote:
Fixed it - I cannot use the module name as a collection index, I needto loop
07-Jan-10
Fixed it - I cannot use the module name as a collection index, I nee
to loop through them checking the Name property of the VBComponent
Phil Hibbs.
Previous Posts In This Thread:
Updating the VBA code in multiple spreadsheets
I asked about this a while ago, now I have a solution. I have use
AutoIt (http://www.autoitscript.com/) , but I think this could also b
done in VB
It can work in one of two ways
1. Run it, select the file that contains the new VBA code, then selec
the Excel spreadsheet to updat
2. Drag and drop a set of files onto a compiled version, and you wil
only be prompted for the VBA cod
The reason I did the latter rather than just multi-selecting in th
File Open Dialog is that I want to be able to process multiple file
across multiple directories, so I search in Explorer and then drag
set of search results onto the executable
The first line of the VBA code file must be in this format
`Name=MyModul
This specifies the module that will be removed, and the newly importe
module will be given this name
This is the code of the AutoIt script
$oExcel = ObjCreate("Excel.Application"
$oExcel.Visible =
$ModuleCode = FileOpenDialog("Select Excel File", "C:\", "VBA Modul
Code (*.txt;*.bas)", 1
If @error Then Exi
$CodeFile = FileOpen( $ModuleCode, 0
$ModuleName = FileReadLine( $CodeFile
FileClose( $CodeFile
If StringLeft( $ModuleName, 6 ) = "'Name=" The
$ModuleName = StringMid( $ModuleName, 7
If $CmdLine[0] > 0 The
$FileName = "
For $i = 1 To $CmdLine[0
$FileName &= "|" & $CmdLine[$i
Nex
$FileName = StringMid( $FileName, 2 ) ; remove the first
characte
Els
$FileName = FileOpenDialog("Select Excel File", "C:\", "Exce
Workbooks (*.xls)", 1
If @error Then Exi
EndI
$xlscount =
For $xls In StringSplit( $FileName, "|", 2
ReplaceMacro( $xls, $ModuleName, $ModuleCode
$xlscount +=
Nex
MsgBox( 1, "Finished", $xlscount & " files updated"
Els
MsgBox( 1, "Error", "First line must begin with 'Name=
EndI
Func ReplaceMacro( $FileName, $ModuleName, $ModuleCode
$oExcel.WorkBooks.Open($FileName
$oModules = $oExcel.ActiveWorkbook.VBProject.VBComponent
For $oModule in $oModule
If $oModule.Type = 1 And $oModule.Name = $ModuleName The
$oModules.Remove( $oModule
EndI
Nex
$oModules.Import( $ModuleCode
$oModules = $oExcel.ActiveWorkbook.VBProject.VBComponent
$ModuleCount =
For $oModule in $oModule
$ModuleCount +=
If $ModuleCount = $oModules.Count The
$oModule.Name = $ModuleNam
EndI
Nex
$oExcel.ActiveWorkbook.Sav
$oExcel.ActiveWorkbook.Clos
$oExcel.Qui
EndFun
-
Phil Hibbs.
I am now trying to port this to Excel, and I am hitting a problem wherethe
I am now trying to port this to Excel, and I am hitting a problem wher
the Remove method fails with "Object does not support this method o
property"
Sub UpdateVBA(
Dim oExcel As Applicatio
Dim oComponent As Objec
Set oExcel = New Excel.Applicatio
Set oBook = oExcel.Workbooks.Open("C:\Test.xls", 0, False, , ,
True
Set oComponent = oBook.VBProject.VBComponents("TestModule"
oBook.VBProject.VBComponents.Remove (oComponent) ' <== FAI
oBook.VBProject.VBComponents.Import ("C:\TestModule.txt"
oBook.VBProject.VBComponent
(oBook.VBProject.VBComponents.Count).Name = "TestModule
oBook.Clos
oExcel.Qui
End Su
Any ideas
Phil Hibbs.
Fixed it - I cannot use the module name as a collection index, I needto loop
Fixed it - I cannot use the module name as a collection index, I nee
to loop through them checking the Name property of the VBComponent
Phil Hibbs.
Submitted via EggHeadCafe - Software Developer Portal of Choice
Generic Feed Parsers Redux
http://www.eggheadcafe.com/tutorial...6-acd41f462063/generic-feed-parsers-redu.aspx
Phil Hibbs wrote:
Fixed it - I cannot use the module name as a collection index, I needto loop
07-Jan-10
Fixed it - I cannot use the module name as a collection index, I nee
to loop through them checking the Name property of the VBComponent
Phil Hibbs.
Previous Posts In This Thread:
Updating the VBA code in multiple spreadsheets
I asked about this a while ago, now I have a solution. I have use
AutoIt (http://www.autoitscript.com/) , but I think this could also b
done in VB
It can work in one of two ways
1. Run it, select the file that contains the new VBA code, then selec
the Excel spreadsheet to updat
2. Drag and drop a set of files onto a compiled version, and you wil
only be prompted for the VBA cod
The reason I did the latter rather than just multi-selecting in th
File Open Dialog is that I want to be able to process multiple file
across multiple directories, so I search in Explorer and then drag
set of search results onto the executable
The first line of the VBA code file must be in this format
`Name=MyModul
This specifies the module that will be removed, and the newly importe
module will be given this name
This is the code of the AutoIt script
$oExcel = ObjCreate("Excel.Application"
$oExcel.Visible =
$ModuleCode = FileOpenDialog("Select Excel File", "C:\", "VBA Modul
Code (*.txt;*.bas)", 1
If @error Then Exi
$CodeFile = FileOpen( $ModuleCode, 0
$ModuleName = FileReadLine( $CodeFile
FileClose( $CodeFile
If StringLeft( $ModuleName, 6 ) = "'Name=" The
$ModuleName = StringMid( $ModuleName, 7
If $CmdLine[0] > 0 The
$FileName = "
For $i = 1 To $CmdLine[0
$FileName &= "|" & $CmdLine[$i
Nex
$FileName = StringMid( $FileName, 2 ) ; remove the first
characte
Els
$FileName = FileOpenDialog("Select Excel File", "C:\", "Exce
Workbooks (*.xls)", 1
If @error Then Exi
EndI
$xlscount =
For $xls In StringSplit( $FileName, "|", 2
ReplaceMacro( $xls, $ModuleName, $ModuleCode
$xlscount +=
Nex
MsgBox( 1, "Finished", $xlscount & " files updated"
Els
MsgBox( 1, "Error", "First line must begin with 'Name=
EndI
Func ReplaceMacro( $FileName, $ModuleName, $ModuleCode
$oExcel.WorkBooks.Open($FileName
$oModules = $oExcel.ActiveWorkbook.VBProject.VBComponent
For $oModule in $oModule
If $oModule.Type = 1 And $oModule.Name = $ModuleName The
$oModules.Remove( $oModule
EndI
Nex
$oModules.Import( $ModuleCode
$oModules = $oExcel.ActiveWorkbook.VBProject.VBComponent
$ModuleCount =
For $oModule in $oModule
$ModuleCount +=
If $ModuleCount = $oModules.Count The
$oModule.Name = $ModuleNam
EndI
Nex
$oExcel.ActiveWorkbook.Sav
$oExcel.ActiveWorkbook.Clos
$oExcel.Qui
EndFun
-
Phil Hibbs.
I am now trying to port this to Excel, and I am hitting a problem wherethe
I am now trying to port this to Excel, and I am hitting a problem wher
the Remove method fails with "Object does not support this method o
property"
Sub UpdateVBA(
Dim oExcel As Applicatio
Dim oComponent As Objec
Set oExcel = New Excel.Applicatio
Set oBook = oExcel.Workbooks.Open("C:\Test.xls", 0, False, , ,
True
Set oComponent = oBook.VBProject.VBComponents("TestModule"
oBook.VBProject.VBComponents.Remove (oComponent) ' <== FAI
oBook.VBProject.VBComponents.Import ("C:\TestModule.txt"
oBook.VBProject.VBComponent
(oBook.VBProject.VBComponents.Count).Name = "TestModule
oBook.Clos
oExcel.Qui
End Su
Any ideas
Phil Hibbs.
Fixed it - I cannot use the module name as a collection index, I needto loop
Fixed it - I cannot use the module name as a collection index, I nee
to loop through them checking the Name property of the VBComponent
Phil Hibbs.
Submitted via EggHeadCafe - Software Developer Portal of Choice
Generic Feed Parsers Redux
http://www.eggheadcafe.com/tutorial...6-acd41f462063/generic-feed-parsers-redu.aspx