Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 17
Default Code to edit code

Is it possible to write code to open an excel workbook,
access the code (that is password protected), perform a
Find/Replace All, and close the workbook, saving changes?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Code to edit code

It's possible to open an Excel workbook and edit the code - but, AFAIK, only
if the code is not protected.

I don't think there is anyway programatically to unprotect the code, even if
you know the password.

Tim

"Sam" wrote in message
...
Is it possible to write code to open an excel workbook,
access the code (that is password protected), perform a
Find/Replace All, and close the workbook, saving changes?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Code to edit code


PS - for info on how to programatically edit modules etc see Chip Pearson's
website at:
http://www.cpearson.com/excel/vbe.htm

Tim

"Tim Barlow" wrote in message
...
It's possible to open an Excel workbook and edit the code - but, AFAIK,

only
if the code is not protected.

I don't think there is anyway programatically to unprotect the code, even

if
you know the password.

Tim

"Sam" wrote in message
...
Is it possible to write code to open an excel workbook,
access the code (that is password protected), perform a
Find/Replace All, and close the workbook, saving changes?





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Code to edit code

Sam,

Assuming your code is unprotected, you could use this code:

I've added a second condition so that it doesn't modify it's own procedure
(Not .ProcOfLine(i, vbext_pk_Proc) = "testit" )

Sub testit()
Dim strFind As String, strReplace As String, vbc As VBComponent, i As
Long, j As Long

strFind = "drink me"
strReplace = "eat me"

For Each vbc In ThisWorkbook.VBProject.VBComponents
With vbc.CodeModule
For i = 1 To .CountOfLines
j = InStr(1, .Lines(i, 1), strFind, vbTextCompare)
If j 0 And Not .ProcOfLine(i, vbext_pk_Proc) = "testit"
Then _
.ReplaceLine i, Replace(.Lines(i, 1), strFind,
strReplace, , , vbTextCompare)
Next
End With
Next
End Sub

Cheers


"Sam" wrote in message
...
Is it possible to write code to open an excel workbook,
access the code (that is password protected), perform a
Find/Replace All, and close the workbook, saving changes?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
edit & configure add button & code [email protected] uk Excel Discussion (Misc queries) 1 November 23rd 08 08:28 PM
Edit this macro code to loop and end GarToms Excel Discussion (Misc queries) 1 January 27th 06 12:50 PM
edit hyperlink code cont from 12/8/04 doug Excel Discussion (Misc queries) 4 December 17th 04 11:51 PM
Can I edit .iqy file from code? Nathan Gutman Excel Programming 2 December 18th 03 08:29 PM
Code Edit Todd Huttenstine[_2_] Excel Programming 1 December 12th 03 03:34 AM


All times are GMT +1. The time now is 03:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"