PDA

View Full Version : Simple Dynamic External Variables



sps
01-05-2012, 01:56 AM
I got fed up with a plugin developer and decided to create a pared down version on my own. I’m the worst kind of coder. I never learned how to do it correctly and I only program every couple of years out of necessity. Usually Access or Flash, etc. and never anything advanced.

What I need is a simple routine that archives Outlook messages to my project folders and renames them with date stamps and other information.

I found a routine here that does this and I modified it to work as I need. It copies the message as a MSG file to a folder selected using the BrowseForFolder function that many scripts here use. The one I cribbed uses the OpenAt variant for setting the default folder location in the dialog box.

This all works quite well but I’d like to add one more thing before patting myself on the back.

I’d prefer to have a list box of historically chosen pathnames for me to choose from before initiating the file copy, and a browse button that allows me to choose one if it’s not on the list and have it added automatically once I’m done.

The external file needs to be a simple text file that I can manually clean up as time goes by.

Any ideas or pushes in the right direction?

JP2112
01-05-2012, 10:17 AM
A listbox will require a userform.

You mention an "external file" but I have no idea what that refers to. Do you mean you want to store the list of pathnames in a text file?

sps
01-05-2012, 12:33 PM
A listbox will require a userform.

You mention an "external file" but I have no idea what that refers to. Do you mean you want to store the list of pathnames in a text file?

Yes. I've seen other code samples where users are creating tables or other external data types that serve their purposes. I'd rather use something similar to an INI or CFG file that I can cull values from with Notepad.

sps
01-08-2012, 12:57 AM
Maybe there's a more active subforum for this?

Sebastian H
01-23-2012, 03:03 PM
I hope you're still around; maybe people were just in vacation, or they got scared by your self-deprecating introduction. Anyway, here's the basic code for your case:
Private Sub UserForm_Initialize()
Dim NewLine As String

Open "C:\SomeFolder\folders.txt" For Input As #1
While Not EOF(1)
Line Input #1, NewLine
ListBox1.AddItem NewLine
Wend
Close 1
End Sub
This assumes that you created a text file at C:\SomeFolder\folders.txt and a form with a listbox (keeping the default name 'ListBox1'). The above Sub just goes in the code window for that form.