Random signature from text file

C

chowse

Hi,
This is my first post to this forum, and my first attempt at VBA in Outlook.

I want to:
generate a random number between X and Y
open a text file for reading
read the line from the file that corresponds to the random number
concatenate some text to that line
add the result to the signature of an email

Can I do that with VBA?
Could someone point me to some code examples to get me started?

TIA,
Charles
 
M

Michael Bauer [MVP - Outlook]

This returns a random value:

Dim MaxValue&, MinValue&, Result&
Randomize
Result = Int((MaxValue - MinValue + 1) * Rnd + MinValue)

Here's an example for reading a file:
http://www.vboffice.net/sample.html?lang=en&mnu=1&smp=14&cmd=showitem

You can split the content of the file into an array with the Split function,
then access, for instance, array(2) as line 3.

The body of an email is available via the Body or HTMLBody property.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Wed, 9 Dec 2009 14:34:01 -0800 schrieb chowse:
 
C

Charles Howse

I'm the OP, had to create a new profile when I lost my password.
I've got the following, it's failing at the path to Guy.txt with a syntax error:

Sub Guy()
Dim MaxValue&, MinValue&, Result&
MaxValue = 200
MinValue = 1

Randomize
Result = Int((MaxValue - MinValue + 1) * Rnd + MinValue)

Dim lFileNr As Long
Dim sText As String

lFileNr = C:\Users\Charles\Documents\Sigs\Guy.txt

Open sPath For Binary As #lFileNr
sText = Space$(LOF(lFileNr))
Get #lFileNr, , sText

ReadFile = sText

End Sub



mb wrote on Thu, 10 December 2009 02:1
 
M

Michael Bauer [MVP - Outlook]

Please follow the mentioned example. It doesn't say to write the path into
the lFileNr variable. If you take the example as it is, call the function
with the path:

Dim Content$
Content=ReadFile("c:\users...")

Now Content contains the content of the file.

--
Best regards
Michael Bauer - MVP Outlook
Manage and share your categories:
<http://www.vboffice.net/product.html?pub=6&lang=en>


Am Sat, 02 Jan 2010 09:12:09 -0500 schrieb Charles Howse:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top