Need userform content to placed in a word document

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
626
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I have a userform created in word 2010. It asks the user for certain information then it adds the content of the form into the blank word document. The code below is the current code. I haven't written anymore yet, until I figure out how to add it to the word document. As you can see, the document formatting is already preassigned. I just need to figure out how to add the content from the userform to the word document. Any help would be greatly appreciated, is what I am wanting to do is even possible? Thank You

Code:
Private Sub cmdbtnSubmit_Click()
    Application.Templates.LoadBuildingBlocks
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    Selection.Font.Name = "Arial"
    Selection.Font.Bold = True
    Selection.Font.Size = 48
    'Selection.PasteAndFormat (wdFormatOriginalFormatting)
    'Selection.MoveUp Unit:=wdLine, Count:=15
 
   Dim sLineSelect As String

    Select Case True
        Case Is = optSt
            sLineSelect = "St"
        Case Is = optUh2
            sLineSelect = "Uh2"
        Case Is = optKr
            sLineSelect = "Kr"
        Case Is = optIA
            sLineSelect = "IA"
        Case Is = optUh5
            sLineSelect = "Uh5"
        Case Is = optPouch
            sLineSelect = "Pouch"
    End Select

    
End Sub
 
How can I tell? Looking at the project explorer in Word 2007 I see two things a plus sign that has the word "Normal" and a plus sign that has the words "Project(Product_placard)" Which is the name of the document inside the parenthesis.
Here's the layout in Office Word 2007.
  • Normal
    • Microsoft Word Objects
      • ThisDocument
    • Forms
      • Userform1
    • Modules
      • Module2
  • Project(Project_placard)
    • Microsoft Word Objects
      • ThisDocument
    • References
      • Reference to Normal
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Your userform and code module (Module2) have both been inserted into Word's Normal template. At the very least, you need to export the userform from there and import it into to your 'Product_placard' document. Depending on what's in Module2, you may need to export the code from there also and import it into your 'Product_placard' document. Again, depending on what's in the 'This Document' code module of the Normal template, you might even need to copy some or all of that into your 'Product_placard' document's 'This Document' code module.
 
Upvote 0
Ok...standby...yup that worked. After confirming this on another computer that is running Office 365. I did notice though, that some of the captions in the labels on the userform are not displaying all the text (its like there cut off). I'm assuming that has something to do with the screen resolution settings. Is there anyway to fix this issue, so the userform is displayed the same no matter what computer it is run on? This occasionally happens on my Excel userforms too. If this question needs to be reposted in another forum, can you kindly direct me to where it needs to be posted. Thank you for the reply.
 
Upvote 0
I made a modification to my userform, which is now giving me a Run-time error '13': Type mismatch
I added a textbox so the user can enter in their desired font size they would like to use. Here's the new code.
VBA Code:
Private Sub UserForm_Initialize()
    Application.Templates.LoadBuildingBlocks
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    Selection.Font.Name = "Arial"
    Selection.Font.Bold = True
    Selection.Font.Size = Me.txtbxFntSz.Value
End Sub
The error occurs on the last line
Code:
Selection.Font.Size = Me.txtbxFntSz.Value
I have tried the following and none of them remove the runtime error. Here's what I have tried:
Code:
Selection.Font.Size = Userform1.txtbxFntSz.Value
Selection.Font.Size = CInt(Me.txtbxFntSz.Value)
Thank you for any help offered.
 
Upvote 0
I'd have thought it would be sufficient to have:
Selection.Font.Size = txtbxFntSz.Value
That's on the proviso, of course, that txtbxFntSz.Value contains a number from 1 to 72 in increments of 0.5.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top