Random signature from text file

Status
Not open for further replies.
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/en/developers/open-and-save-files

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

Am Wed, 9 Dec 2009 14:34:01 -0800 schrieb 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
 
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:11
> 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/sm p=14&

> 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

> > >

> Am Wed, 9 Dec 2009 14:34:01 -0800 schrieb 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
 
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

Am Sat, 02 Jan 2010 09:12:09 -0500 schrieb 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:11
> > 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/sm p=14&
>

>> 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
>

>> >> >>

>

>
>> Am Wed, 9 Dec 2009 14:34:01 -0800 schrieb 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


> .
>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
S.Champ Please help? I've imported a random workcalendar I dont even know who's. Can I undo it? and then I need to re-sync the google one again. Its a mess:( Using Outlook 2
L Wierd Office 365 Contact unable to edit body of random contacts Using Outlook 5
mikolajek Random message selected after hard delete Using Outlook 4
I Random Chinese characters in email copied from a pst file. Exchange Server 2016 Public Folder Exchange Server Administration 1
T Random problem in VBA macro Outlook VBA and Custom Forms 6
A Mysterious random appearance of empty unsent email Using Outlook 3
J outlook meeting request random people are deleted Using Outlook 2
M Being prompted for random credentials Using Outlook 23
A Help with random numbers in autocomplete emails Exchange Server Administration 3
I Outlook moving random messages from folders back to the inbox Using Outlook 1
D VBA code to select a signature from the signatures list Outlook VBA and Custom Forms 3
DDB VBA to Auto Insert Date and Time in the signature Outlook VBA and Custom Forms 2
M HTML email signature in Outlook Using Outlook 3
B Adding signature to bottom of VBA reply email Outlook VBA and Custom Forms 1
Martull Forced signature when multiple accounts exist Outlook VBA and Custom Forms 4
B Importing business card into Outlook for SIgnature Using Outlook 1
H Custom Signature Not Displayed When Account Selected Outlook VBA and Custom Forms 10
N How to remove signature formatting from Text in Word (accidentally taken from Outlook) Using Outlook 0
M Help sending email but removing signature via VBA Outlook VBA and Custom Forms 5
JackBlack What tools do you use to create the signature for email? Using Outlook 3
N Signature displaying incorrectly in email Using Outlook 1
Morgan Fowler Remove Signature Using Outlook 1
L Block email signature image Using Outlook 1
N Does a Shared Folder Policy override a Digital Signature Setting for macros? Outlook VBA and Custom Forms 6
J Remove extra line above signature in reply Outlook VBA and Custom Forms 5
C Macro to send email after changing from address and adding signature Outlook VBA and Custom Forms 1
skylark53 Loss of default format on deleting signature Using Outlook 5
V incorrect html signature printed Using Outlook 2
G Linked (online) signature images Using Outlook 5
O VBA to change message format and add formatted signature Outlook VBA and Custom Forms 1
Brendan.Z Outlook 2013 signature editing issue Using Outlook 3
J Outlook 2013 crashes saving VBA & clicking tools | digital signature Outlook VBA and Custom Forms 1
JorgeDario how to check a MailItem has a digital signature (SMIME) with vba? Outlook VBA and Custom Forms 1
blashmet Outlook Signature Distorted in Other Email Clients Using Outlook 9
B Oultlook 2007 Signature back ups Using Outlook 4
Ramy Wassef Signature Using Outlook 1
SirFishAlot SIGNATURE EMBED ISSUE OUTLOOK 2013 BCM (Business Contact Manager) 10
J Macro generating email using default signature and hyperlink Outlook VBA and Custom Forms 5
G Onding e-mail with wrong signature Using Outlook 0
T Setting a Default Subject from a certain Signature Using Outlook 0
B Signature Reply Issue Using Outlook 1
D Digital Signature Exchange Server Administration 1
S signature in meeting request Using Outlook 2
C Unusual Signature & Spell Check Query Using Outlook 1
R automatic signature Using Outlook 0
L Auto Reply Signature Using Outlook 5
X Outlook 2007+ Changing signature also changes subject? Using Outlook 9
L Automatically change signature based on to / cc field (@customerdomain.com) Using Outlook 2
S Outlook 2k/2k3 Reply or Forward: Signature image replaced by original sender Using Outlook 3
E Outlook Signature GPO issues Using Outlook 2

Similar threads

Back
Top