+ Reply to Thread
Results 1 to 2 of 2

VBA: formatting a word document/RTF file from VBA

  1. #1
    Registered User
    Join Date
    03-27-2019
    Location
    Texas
    MS-Off Ver
    Excel 2016
    Posts
    5

    VBA: formatting a word document/RTF file from VBA

    I am trying to format a word document saved as an RTF from VBA after already posting data into it in the same macro.
    The path output I am using is saved as a string and not an object which I think might be causing the problem but im not sure. My code is below.


    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"

    Close #1
    Close #2

    End Sub



    The values in quotations are saved named ranges in my excel document with the location and names of the files I am using.
    I am trying to format the word document to have font size of 14 and top/bottom margins of 2.25.
    My guess so far was to use the WITH function in VBA but I was not having any luck.

    'With PrintOutput.Object.PageSetup
    ' .TopMargin = wrdApp.InchesToPoints(2.25)
    ' .BottomMargin = wrdApp.InchesToPoints(2.25)
    ' .Font.Size = 14
    'End With


    If anyone has any tips or any other advice in general I would greatly appreciate it.

    Thanks!

  2. #2
    Registered User
    Join Date
    03-27-2019
    Location
    Texas
    MS-Off Ver
    Excel 2016
    Posts
    5

    Re: VBA: formatting a word document/RTF file from VBA

    I have now figured out how to change the margins but now the font size command will not work.
    This is what I have so far.

    Please Login or Register  to view this content.

    Running this with the font command gives an error message "Object doesnt support this property or method".
    If anyone has any tips or anything that could help please let me know, any feedback is appreciated.
    Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Formatting a word document using macros
    By klsemory in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-10-2016, 01:27 PM
  2. VBA for Insert Object >>Create from File>>Choose File. In Word Document
    By kt1993 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-08-2015, 03:43 PM
  3. Copy data to a new Word document then apply formatting
    By ormerods in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-25-2013, 07:00 AM
  4. Import data from Word document and keep original formatting
    By dougdrex in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 06-11-2013, 03:52 PM
  5. Add text to Existing Word Document if it Doesn't exist create Word Document
    By unstable81 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-10-2013, 12:15 AM
  6. Replies: 0
    Last Post: 06-15-2011, 02:22 PM
  7. Import file to Word document
    By Y Y in forum Excel General
    Replies: 1
    Last Post: 10-21-2005, 01:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1