Random signature from text file

  • Thread starter Thread starter chowse
  • Start date Start date
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
 
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:
 
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
 
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:
 
Back
Top