Consulting

Results 1 to 2 of 2

Thread: Excel VBA- Disable Automatically resize option when converting to Word

  1. #1

    Excel VBA- Disable Automatically resize option when converting to Word

    I am using userforms to transfer data into worksheet, then converting it to word document. I created bunch of tables to be fill in userform textboxes. Since some of the comments could be very long, I set those tables as wrap text and autofit row height. While some of the tables are fitting word page, some of them are going beyond of page and some of the borders are going below page without proper format.

    Caadsadadpture.JPG
    1st and 3rd columns have been shrink. I can solve this problem on word as disabling the Automatically resize to fit contents option. However, since I have 10 tables, I need to disable this option from Excel vba.

    How could I fit those borders into word document without overflow to the other pages and without shrinking.

    Sub TestingMacAndWin1()
    Dim appWD As Object
    Dim wddoc As Object
    
    On Error Resume Next
    Set appWD = GetObject(, "Word.application")    'gives error 429 if Word is not open
    If Err = 429 Then
        Set appWD = CreateObject("Word.application")    'creates a Word application
        Err.Clear
    End If
    
    Set wddoc = appWD.Documents.Add
    appWD.Visible = True
    
    With appWD.ActiveDocument.PageSetup
        .Orientation = 1
        .Content.Style = .Styles("No Spacing")
        .TopMargin = appWD.InchesToPoints(0.3)
        .BottomMargin = appWD.InchesToPoints(0.3)
        .LeftMargin = appWD.InchesToPoints(0.3)
        .RightMargin = appWD.InchesToPoints(0.3)
        .InsertBreak Type:=0
    End With
    
    
    
    Sheets("Report").Range("N16").CurrentRegion.Copy
    appWD.Selection.Paste
    
    With appWD.Selection
        .AllowAutoFit = False
        .Collapse Direction:=0
    End With
    
    
    
    appWD.Activate
    
    End Sub

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    perhaps you should loop all the tables in the document.

    https://msdn.microsoft.com/en-us/vba...or-method-word
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

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
  •