I'm writing a macro that takes a text file containing code and copies it behind sheet1 of an existing workbook. It works fine on my computer but every time I run it on someone else's computer, Excel gives a fatal error on the following line of code it is importing.... Not sure why.
Dim rsData as ADODB.Recordset
Below is my vba code and I also attached the text file.
Any help is appreciated.Add Code Code:
Sub UpdateThisWorkbook() On Error GoTo DownHere Dim VBProj As VBIDE.VBProject Dim VBComp As VBIDE.VBComponent Dim CodeMod As VBIDE.CodeModule Dim LineNum As Long Dim oFS Dim FsFile Set FsFile = CreateObject("Scripting.FileSystemObject") Set oFS = FsFile.OpenTextFile(ThisWorkbook.Path + "\copy sheet1 code.txt") Set VBProj = ActiveWorkbook.VBProject Set VBComp = VBProj.VBComponents("sheet1") Set CodeMod = VBComp.CodeModule 'This adds the ADO references. VBProj.References.AddFromFile "C:\Program Files\Common Files\system\ado\msado15.dll" VBProj.References.AddFromFile "C:\Program Files\Common Files\system\ado\msador15.dll" CodeMod.DeleteLines 1, CodeMod.CountOfLines With CodeMod Do Until oFS.AtEndOfStream LineNum = LineNum + 1 stext = oFS.ReadLine .InsertLines LineNum, stext Loop End With Exit Sub DownHere: MsgBox Err.Description, vbOKOnly, Format(Err.Number) Resume Next End Sub
Thanks!
Chrissy




Reply With Quote