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!

How do I use an "ini." to point to an address to save my workbook? 1

Status
Not open for further replies.

coolcarls

Technical User
Jan 19, 2002
182
US
I have an excel workbook with 4 sheets and 3 userforms, there's a bunch of vba too. I put this code in one of the worksheet deactivate thingy

Private Sub Worksheet_Deactivate()
ThisWorkbook.SaveAs ("C:\Projects\TEMPLATES\BOL-INV.xlt")
End Sub

Now I want to have this workbook on other computers on my network and so the "save to" address will be different, can I use an "ini" type file to point to an address & if so how?

Also, if you know the answer to that question, you'll know the answer to this one too, how do I make the vba code password protected so no one can even view it?

thanks a lot,



Carl
 
for the INI file question...

Code:
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Sub Form_Load()
    'KPD-Team 1999
    'URL: [URL unfurl="true"]http://www.allapi.net/[/URL]
    'E-Mail: KPDTeam@Allapi.net
    Dim Ret As String, NC As Long
    'Write the setting to the file (c:\test.ini) under
    '   Project1 -> Keyname
    WritePrivateProfileString App.Title, "KeyName", "This is the value", "c:\test.ini"
    'Create a buffer
    Ret = String(255, 0)
    'Retrieve the string
    NC = GetPrivateProfileString(App.Title, "KeyName", "Default", Ret, 255, "C:\test.ini")
    'NC is the number of characters copied to the buffer
    If NC <> 0 Then Ret = Left$(Ret, NC)
    'Show our string
    MsgBox Ret
    'Delete the file
    Kill &quot;c:\test.ini&quot;
End Sub

for the code protection...

Open Visual Basic Editor (Alt-F11)
From the menu, click on Tools-->Properties
Choose the Protection tab
Check the box 'lock project for viewing'
etc., etc., etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top