Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

modifying code on the fly

Status
Not open for further replies.

RobBroekhuis

Technical User
Oct 15, 2001
1,971
US
Hi,
I'm writing a short application that requires some data storage (just a few filenames) that gets retained when the Office application is shut down. In Excel that's easy - I just write to ThisWorkbook in personal.xls. Now I'm trying to do the same in Word, figured out how to store things in ThisDocument in normal.dot, only to find that, since ThisDocument is used as a template for new documents, this isn't such a great idea.
Question #1: Is there a different convenient location to write to, without using a separate text file?

Question #2: I decided to try to do this by modifying the code in the module I'm writing (in normal.dot) on the fly. I've heard this is tricky, but I figured I'd give it a go. Problem is, VBE doesn't seem to know how to handle this. My code example:
Code:
Sub addFF()
    Dim l As Long, c As Long, ll As Long, lc As Long, b As Boolean
    With Application.VBE.VBProjects("normal").VBComponents("Frequentfiles").CodeModule
       b = .Find("FrequentOpen" & 1, l, c, ll, lc)
       .ReplaceLine(l + 5, "    Documents.Open c:\autoexec.bat")
    End With
End Sub
VBE says I have a syntax error in the .replaceline line ("Compile error: expected ="), but the replaceline method does not return a value, so that I get a run-time error if I try to fool VBE by adding "x=" to the line. Why is VBE confused? Do I need to add a reference? By the way, the .find line has a similar problem (syntax error when I leave the "b =" out), but luckily that method does return a value so that I can assign it to a dummy variable.
I'd appreciate your help!
 
Never mind the second question - I realize the error of my ways (ditch the parentheses). Still interested in the first question, though!
Rob
 
Have you considered the registry? WritePrivateProfileString?
 
Larry,
Thanks for the suggestion. I'll have to look into that - not something I've done before. The code modification approach works now, so I can explore other options at my leisure.
Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top