installing VB script

W

windandwaves

Hi Gurus

I have written a piece of VB script (see below). I want to send this to a
client so that he can install it. My question is, how can I send that best.
I know they have access so should i put it in access and then export from
there into outlook?

Any help greatly appreciated (this is all new to me)



Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties.
Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem
Set olApp = Outlook.Application
'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)

With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.HTMLBody = go()
.Display
End With
End Sub



Function go()
Dim Fs
Dim A
Dim PathandFile As String
'-
PathandFile = "c:\testfile.htm"
Set Fs = CreateObject("Scripting.FileSystemObject")
Set A = Fs.OpenTextFile(PathandFile)
'read rest of the file
Do While A.AtEndOfStream <> True
ReadFile = ReadFile & Trim(A.ReadLine)
Loop
A.Close
'-check last line
go = strtext
End Function
 
S

Sue Mosher [MVP-Outlook]

Copy and paste it into a Notepad text file and email that file to him along with instructions for how to copy and paste the code into a module in the Outlook VBA environment.

FYI, there is a newsgroup specifically for general Outlook programming issues "down the hall" at microsoft.public.outlook.program_vba or, via web interface, at http://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public.outlook.program_vba

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
W

windandwaves

Sue said:
Copy and paste it into a Notepad text file and email that file to him
along with instructions for how to copy and paste the code into a
module in the Outlook VBA environment.

Hey Sue,
thank you for your reply. much appreciated. is there anything more
sophisticated then the method you outline above? my client is a novice,
novice and I would prefer a simple installer as it would look more
professional.

TIA

PS my next question is how I can create a button in outlook that calls the
code.
 
S

Sue Mosher [MVP-Outlook]

There is no programmatic way to install VBA code. Maybe you should be building them a COM addin instead? Or take out the variable data typing so you can redo it as a VBSCript .vbs file.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
W

windandwaves

Sue said:
There is no programmatic way to install VBA code. Maybe you should be
building them a COM addin instead? Or take out the variable data
typing so you can redo it as a VBSCript .vbs file.

What would you recommend. I checked out Com Addin and I need all sorts of
software for that I believe. VBscript may be a better option. Do you know
any good places where I can find help for this.

Thanks again.
 
S

Sue Mosher [MVP-Outlook]

This newsgroup covers VBScript applications of Outlook programming techniques, as well as VBA. Basically, all you need to do is:

-- remove the data typing from variable and procedure declarations
-- declare any Outlook constants or use the literal values
-- instantiate an Outlook.Application object with CreateObject()

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
W

windandwaves

Sue said:
This newsgroup covers VBScript applications of Outlook programming
techniques, as well as VBA. Basically, all you need to do is:

-- remove the data typing from variable and procedure declarations
-- declare any Outlook constants or use the literal values
-- instantiate an Outlook.Application object with CreateObject()


Here is the VB script that I created, it works a treat in XP. Any further
comments greatly appreciated.

Dim theApp
Set theApp = WScript.CreateObject("Outlook.Application")
CreateHTMLMail(theApp)
Public Sub CreateHTMLMail(olapp)
'Creates a new e-mail item and modifies its properties.
'Dim olApp As Outlook.Application
Dim objMail 'As Outlook.MailItem
'Set olApp = Outlook.Application
'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)
With objMail
'Set body format to HTML
..BodyFormat = 2' olFormatHTML
..HTMLBody = gettemplate("")
..Display
End With
End Sub


Private Function gettemplate(PathandFile)
Dim Fs
Dim A
Dim Readfile 'As String
'-
if PathandFile <> "" then
Set Fs = CreateObject("Scripting.FileSystemObject")
Set A = Fs.OpenTextFile(PathandFile)
'read rest of the file
Do While A.AtEndOfStream <> True
Readfile = Readfile & Trim(A.ReadLine)
Loop
A.Close
'-check last line
else
readfile = "<html><head><title>test</title><body style=" & chr(34) & "
background-color: red;" & chr(34)& ">off you go</body><html>"
end if
gettemplate = Readfile
End Function


Is there a way to have an html document embedded in this document without
having to be so clumsy with all the " & chr(34)& "??? I would love to have
a way to include a text-block in the script.

TIA
 
S

Sue Mosher [MVP-Outlook]

An alternative to putting in Chr(34) is to use a function:

Function Quote(text)
Quote = Chr(34) & text & Chr(34)
End Function

and thus

readfile = "<html><head><title>test</title><body style=" & _
Quote("background-color: red;") & ">off you go</body><html>"

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


windandwaves said:
Sue said:
This newsgroup covers VBScript applications of Outlook programming
techniques, as well as VBA. Basically, all you need to do is:

-- remove the data typing from variable and procedure declarations
-- declare any Outlook constants or use the literal values
-- instantiate an Outlook.Application object with CreateObject()


windandwaves said:
Sue Mosher [MVP-Outlook] wrote:
There is no programmatic way to install VBA code. Maybe you should
be building them a COM addin instead? Or take out the variable data
typing so you can redo it as a VBSCript .vbs file.

What would you recommend. I checked out Com Addin and I need all
sorts of software for that I believe. VBscript may be a better
option. Do you know any good places where I can find help for this.

Thanks again.

Nicolaas


Here is the VB script that I created, it works a treat in XP. Any further
comments greatly appreciated.

Dim theApp
Set theApp = WScript.CreateObject("Outlook.Application")
CreateHTMLMail(theApp)
Public Sub CreateHTMLMail(olapp)
'Creates a new e-mail item and modifies its properties.
'Dim olApp As Outlook.Application
Dim objMail 'As Outlook.MailItem
'Set olApp = Outlook.Application
'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)
With objMail
'Set body format to HTML
.BodyFormat = 2' olFormatHTML
.HTMLBody = gettemplate("")
.Display
End With
End Sub


Private Function gettemplate(PathandFile)
Dim Fs
Dim A
Dim Readfile 'As String
'-
if PathandFile <> "" then
Set Fs = CreateObject("Scripting.FileSystemObject")
Set A = Fs.OpenTextFile(PathandFile)
'read rest of the file
Do While A.AtEndOfStream <> True
Readfile = Readfile & Trim(A.ReadLine)
Loop
A.Close
'-check last line
else
readfile = "<html><head><title>test</title><body style=" & chr(34) & "
background-color: red;" & chr(34)& ">off you go</body><html>"
end if
gettemplate = Readfile
End Function


Is there a way to have an html document embedded in this document without
having to be so clumsy with all the " & chr(34)& "??? I would love to have
a way to include a text-block in the script.

TIA
 
W

windandwaves

Sue Mosher [MVP-Outlook] wrote:
[snip]...[snip]...[snip]

Thank you for all your help Sue, much appreciated. Awesome! I am stoked
with the results.
 

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