PDA

View Full Version : Solved: Delete Lines of Code



SherryO
03-07-2006, 07:47 AM
I'm trying to delete lines of code that I have in Workbook_open before a save. The workbook in question is a template and before it's saved as an xls file I want to delete the open code because it's only necessary once. I'm getting the following errors when I try to execute:
Runtime Error 1004: Programmatic access to Visual Basic Project is not trusted.
and then
Runtime Error 1004: Method 'VBProject' of object '_workbook' failed.

Here is the line of code:
ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule.DeleteLines 25, 1

I would like to delete more than just one line, but I'm stuck here. Any help would be greatly appreciated.
Thanks!!

Jacob Hilderbrand
03-07-2006, 08:07 AM
Programatical access must be allowed for this to work.

Tools | Macros | Security
Trusted Sources
Trust Access to Visual Basic Proect

But a better way may be to just test if the code has run before.

Suppose you have a hidden sheet called Setup then.


If Sheets("Setup").Range("A1").Value = 0 Then
'My Code Here
Sheets("Setup").Range("A1").Value = 1
End If

Then just make the value in the cell 0 and the code will run only one time.

SherryO
03-07-2006, 08:10 AM
You are a peach. I never thought of it that way. Thanks!!!