Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-05-2020, 06:13 AM
SamDsouza SamDsouza is offline Create a Word Document with VBA Windows 10 Create a Word Document with VBA Office 2013
Advanced Beginner
Create a Word Document with VBA
 
Join Date: Aug 2019
Posts: 71
SamDsouza is on a distinguished road
Default Create a Word Document with VBA

Hello

I am getting the above error on below syntax. Though i'v e ran the macro from VBA excel to open the word document

Code:
     objDoc.Range(objDoc.Paragraphs(17).Range.Characters(6).Start, objDoc.Paragraphs(17).Range.Characters(timeLen).End).Font.Bold = True
What i want is to Bold a text Value but the error does not allow.


Please guide with me proper set references, document etc

Code:
Public Sub msWord_Structure()

Dim objWord As Object
Dim txtword As String, sh As Worksheet
Dim objDoc As Object, objSelection As Object
Dim objRange As Object
Dim objTable As Object, objTable2 As Object
Dim para As Object
Dim intRows As Integer
Dim intCols As Integer
  Dim ocell As Object
Dim mpStart As Long
Dim chqNobold As String

Dim txtHeader As String, txtForRtgs As String

chqNobold = txtChqNo.Text
txtHeader = "RTGS/ Request Form" & vbCrLf & vbCrLf
txtword =  Chr(144) & "RTGS                             " & Chr(144) & "" & vbCrLf & vbCrLf
txtForRtgs = "For RTGS"


On Error Resume Next
    Set objWord = GetObject(, "Word.Application")
      If Err Then
           Set objWord = CreateObject("Word.Application")
      End If
    On Error GoTo 0

    Set objDoc = objWord.Documents.Add
        objWord.Visible = True
        objWord.activedocument.Range.Font.Name = "Tahoma"
        objWord.activedocument.Range.Font.Size = "12"
        objWord.activedocument.Paragraphs.SpaceAfter = 0 'InchesToPoints(0.5)
    
 Set objRange = objDoc.Range
    With objRange
        .Collapse Direction:=1
        .Text = txtHeader
          .Font.Name = "Tahoma"
          .Font.Size = "16"
          .Font.Underline = True 'wdUnderlineSingle
          .Paragraphs.SpaceAfter = 0
          .ParagraphFormat.Alignment = 1 'this centers\'wdAlignParagraphCenter '3
    .Collapse Direction:=0
    End With

      
      With objRange
           .Collapse Direction:=1
          .Text = txtword
          .Font.Name = "Tahoma"
          .Font.Size = "12"
          .Paragraphs.SpaceAfter = 0
          .ParagraphFormat.Alignment = 3
          '.Collapse Direction:=wdCollapseEnd
          .Collapse Direction:=0
      End With
      
With objRange
           .Collapse Direction:=1
          .Text = txtForRtgs
          .Font.Name = "Tahoma"
          .Font.Size = "12"
          .Font.Underline = True 'wdUnderlineSingle
          .Paragraphs.SpaceAfter = 0
          .ParagraphFormat.Alignment = 3

      End With
      
            
            intRows = 4: intCols = 2
    Set objTable = objDoc.Tables.Add(objRange, intRows, intCols)
  
   With objTable
          .Columns(1).Width = 200
          .Columns(2).Width = 300

          .Borders.Enable = True
  
       .Rows.HorizontalPosition = 5  '100
       .Rows.VerticalPosition = 10
       .Columns(1).Width = 300
       .Columns(2).Width = 130
       
       .Range.Collapse Direction:=0
       .Borders.Enable = True
              
       Set ocell = .Cell(1, 1).Range
           ocell.Text = "Maximum Limit For  Transaction"
           ocell.End = .Cell(1, 2).Range.End
           ocell.Cells.Merge
           ocell.ParagraphFormat.Alignment = 1
           'ocell.ParagraphFormat.Alignment = wdAlignParagraphCenter
           ocell.End = ocell.End - 1
            
            
      Set ocell = .Cell(2, 1).Range
            ocell.End = ocell.End - 1
            ocell.Text = "IDBI Bank Customer"
            ocell.ParagraphFormat.Alignment = 3
            
      Set ocell = .Cell(2, 2).Range
            ocell.End = ocell.End - 1
            ocell.Text = "No Limit"
            ocell.ParagraphFormat.Alignment = 3
            
      Set ocell = .Cell(3, 1).Range
            ocell.End = ocell.End - 1
            ocell.Text = "Non IDBI Bank Customer & Indo Nepal  Remittance"
            ocell.ParagraphFormat.Alignment = 3
 
      Set ocell = .Cell(3, 2).Range
            ocell.End = ocell.End - 1
            ocell.Text = "Upto INR 50,000/-"
            ocell.ParagraphFormat.Alignment = 3
            
      Set ocell = .Cell(4, 1).Range
            ocell.End = ocell.End - 1
            ocell.Text = "Purpose of Remittance to Nepal - Family Maintenance only"
            ocell.ParagraphFormat.Alignment = 3
            
      Set ocell = .Cell(4, 2).Range
            ocell.End = ocell.End - 1
            ocell.Text = "Yes / No"
            ocell.ParagraphFormat.Alignment = 3
                     ' .Range.Collapse Direction:=wdCollapseEnd
            ocell.Collapse Direction:=0

End With

Dim timeLen As Integer, custNameLen As Integer, RefAcNoLen As Integer, chqNoLen As Integer, MyContactNosLen As Integer
timeLen = (6 + Len(txtTime.Text) + 1)
custNameLen = (16 + Len(cmbMyCustName.Text) + 1)
RefAcNoLen = (13 + Len(txtRefAcNo.Text) + 1)
chqNoLen = (10 + Len(txtChqNo.Text) + 1)
MyContactNosLen = (10 + Len(txtMyContactNos.Text) + 1)
     
     objDoc.Range(objDoc.Paragraphs(17).Range.Characters(6).Start, _
     objDoc.Paragraphs(17).Range.Characters(timeLen).End).Font.Bold = True



txtword = vbNewLine & "Time " & txtTime.Text & vbNewLine & vbNewLine & "Customer Name : " & cmbMyCustName.Text & vbNewLine & vbNewLine & _
"Account No. " & txtRefAcNo.Text & " Chq No. " & txtChqNo.Text & vbNewLine & vbNewLine & "Mobile No" & txtMyContactNos.Text & " Tel No." & _
 vbNewLine & vbNewLine & "Address of Remitter (Mandatory for Non IDBI Bank Customer)___________________________________" & vbNewLine & vbNewLine & _
"__________________________________________" & " Email ID ______________________________________________" & vbNewLine & vbNewLine & _
 vbNewLine & vbNewLine & " Incase of NonIDBI Bank Customer Amount of Cash Deposited _____________________________________" & _
 vbNewLine & vbNewLine '& " Beneficiary Details :"


Set objRange = objDoc.Range
 With objRange
          .Collapse Direction:=0 
          .Text = txtword
          .Font.Name = "Tahoma"
          .Font.Size = "12"
          .Paragraphs.SpaceAfter = 0
          .Collapse Direction:=0 ' wdCollapseStart

      End With
Thanks
SamD
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a Word Document with VBA How do I create an index of every word in a document? jbengal Word 5 11-23-2022 02:17 PM
Create a Word Document with VBA Can I create word wizards with Word 2016 to automate document creation? OkiDoki Word 4 09-30-2016 11:41 AM
Create a Word Document with VBA Word 2010 - How to create a fillable document from a boilerplate document sheaters Word 2 05-04-2016 01:57 PM
How to create a special TOC in word document? gn4619 Word VBA 5 04-29-2015 04:25 PM
How to identify whether Word 2007 was used to create a document saved as Word 2003 noviceatwork Word 0 03-08-2012 06:40 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:49 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft