Consulting

Results 1 to 4 of 4

Thread: VBA: Paragraph formatting an .RTF doc using a WITH function

  1. #1
    VBAX Regular
    Joined
    Mar 2019
    Posts
    9
    Location

    VBA: Paragraph formatting an .RTF doc using a WITH function

    I am using a with function to format an RTF document after putting data into it. I am using a WITH statement and have successfully changed the margins and the font size but the paragraph formats dont seem to update.
    I am somewhat new to using WITH functions and object manipulation in general.
    My code I am using is below.
    It does not error out but instead does not apply any of the paragraph formats. I need 5.75 line spacing with exact spacing as opposed to single or double.

    Option Explicit
    
    
    Sub MyMacro()
    
    
    Dim TargetPath As String
    Dim TargetFile As String
    Dim OutputPath As String
    Dim PrintableOutputFile As String
    Dim PrintOutput As String
    Dim PathInput As String
    
    
    TargetPath = Range("Target_Path").Value
    TargetFile = Range("target_file").Value
    OutputPath = Range("Output_Path").Value
    PrintableOutputFile = Range("printable_output_file").Value
    
    
    PathInput = Range("target_path").Value & "\" & Range("target_file").Value
    PrintOutput = Range("output_path").Value & "\" & Range("printable_output_file").Value
    
    
    Open PathInput For Input As #1
    Open PrintOutput For Output As #2
    
    
    
    
    Print #2, "My Data here"
    
    
    
    
    Set wrdApp = GetObject(PrintOutput)
    
    
    With wrdApp
        .PageSetup.TopMargin = Application.InchesToPoints(2.25)
        .PageSetup.BottomMargin = Application.InchesToPoints(2.25)
        .Content.Font.Size = 14
        .Content.ParagraphFormat.LineSpacingrule = wdlinespaceExactly
        .Content.ParagraphFormat.linespacing = 5.75
    End With
    
    
    
    Close #1
    Close #2
    
    
    
    
    End Sub

    Any help or tips would be greatly appreciated as I am still learning and appreciate all input. Thanks!

  2. #2
    Duplicated post - see the answer to your other copy.
    Graham Mayor - MS MVP (Word)
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    Mar 2019
    Posts
    9
    Location
    I was able to fix the formatting issues but now the WITH function is cutting off some of my data at the end.
    Is there a maximum data amount for VBA objects or something that would cause the data to cut off at the end? I even changed the data and it still cuts off right at the same spot.
    I am thinking that there is either a max character limit on VBA objects or max character limit while using the WITH function.
    If anybody knows anything about either of these things please let me know, I appreciate any and all help. Thanks!

  4. #4
    Without access to the documents in question we would only be guessing.
    Graham Mayor - MS MVP (Word)
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •