Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2007

Tip: Looking for answers? Try searching our database.

Word not saving/running vb code...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James Lee - 24 Dec 2007 14:00 GMT
Hello,

I have a form in Word that has 3 different comboboxes.  In order to
get each item onto the combobox/drop down list I put in this code:

Private Sub UserForm_Initialize()

 ComboBox1.ColumnCount = 1

 'Load data into ComboBox

 ComboBox1.List() = Array(" ", "Content Room A", "Content Room B",
"Content Room C", "Content Rooms AB", "Content Rooms BC", "Content
Rooms ABC")

 ComboBox2.ColumnCount = 1

 'Load data into ComboBox

 ComboBox2.List() = Array(" ", "Conference", "Classroom", "Lecture",
"Horseshoe")

  ComboBox3.ColumnCount = 1

 'Load data into ComboBox

   ComboBox3.List() = Array(" ", "CORP", "ESPN3", "DISNEY")

End Sub

No matter how may times I save the document or anything, when I close
the document and reopen it or send it to someone it won't recognize
the code so the drop down/comboboxes show up as empty.  Any Ideas?

Also, I have a command button that i have that when it is clicked it
opens a new mail message in Outlook with the Word document already
attached.  Is there a way to make it do that as well as inputing the
"TO" email address automatically??  The code I have for the command
button already is this:

Private Sub CommandButton1_Click()
Application.Options.ButtonFieldClicks = 1
Options.SendMailAttach = True
ActiveDocument.SendMail

End Sub

Thanks for any help.
Joe
David Sisson - 26 Dec 2007 15:26 GMT
How are you calling the userform?  With a activex button, menu, or
autoopen?

Here's my email routine.

Private Sub cmdEmail_Click()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim MyPath As String
Dim eCaption$
Dim AddMessage$
Dim Emailname as string

EmailName = "Mr. Bossman"

ufMoveFiles.Caption = "Sending Files to " & EmailName
MyPath = GlLogPath

On Error Resume Next

 If Len(ActiveDocument.Path) = 0 Then
   MsgBox "Document needs to be saved first"
   Exit Sub
 End If

ufMoveFiles.Caption = "Starting Outlook..."

 Set oOutlookApp = GetObject(, "Outlook.Application")
 If Err <> 0 Then
   Set oOutlookApp = CreateObject("Outlook.Application")
   bStarted = True
 End If

 Set oItem = oOutlookApp.CreateItem(olMailItem)

 With oItem
   .To = EmailName
   .Subject = "Additional funding required"

    ufMoveFiles.Caption = "Sending mail"
    AddMessage$ = "Hi Boss, How about a raise?"
   .HTMLBody = AddMessage$
   .Display
 End With

 If bStarted Then
   oOutlookApp.Quit
 End If

 Set oItem = Nothing
 Set oOutlookApp = Nothing

ufMoveFiles.Caption = "Choose Option"
End Sub
James Lee - 26 Dec 2007 17:10 GMT
> How are you calling the userform?  With a activex button, menu, or
> autoopen?
[quoted text clipped - 51 lines]
> ufMoveFiles.Caption = "Choose Option"
> End Sub

Hey Dave,

Thank you so much for getting back to me on this.  I'm not totally
sure if I know what you mean by calling the userform?  I really don't
have that much experience using VB.

Would this code be put into the VB code window in Microsoft Word?

Joe
David Sisson - 26 Dec 2007 19:07 GMT
> Thank you so much for getting back to me on this.  I'm not totally
> sure if I know what you mean by calling the userform?  I really don't
> have that much experience using VB.
>
> Would this code be put into the VB code window in Microsoft Word?

Oh boy, OK.....  I assume you have made a userform hence your code

Private Sub UserForm_Initialize()

From Word, hit Alt-F11.  This brings up the VBA editor.  In the forms
folder on the left, you should have a userform. Double click it.  When
you view the code (F7), you should see the code you posted.

When you need to the code to run, you have to active it by one of the
three ways I listed.

Is the dropdowns you describe on the document itself, or do they
appear in a seperate bowed window (userform).

Why don't you describe your document a little more in detail, so we
can better assist you?

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.