PDA

View Full Version : [SOLVED:] VBA: Paragraph formatting an .RTF doc using a WITH function



mh2020
03-28-2019, 07:30 AM
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!

gmayor
03-29-2019, 03:26 AM
Duplicated post - see the answer to your other copy.

mh2020
03-29-2019, 02:57 PM
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!

gmayor
03-29-2019, 09:37 PM
Without access to the documents in question we would only be guessing.