Word not saving/running vb code...

J

James Lee

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
 
D

David Sisson

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
 
J

James Lee

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

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
 
D

David Sisson

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?
 

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