简体   繁体   中英

Convert Text to Table VBA MS Word - AutoFit to Contents not working

I am trying to automate conversion of text to a table. When I selected "Auto-fit to contents" while recording a macro, I got the following code:

    WordBasic.TextToTable ConvertFrom:=1, NumColumns:=2, NumRows:=6, _
    InitialColWidth:=wdAutoPosition, Format:=0, Apply:=1184, AutoFit:=1, _
    SetDefault:=0, Word8:=0, Style:="Table Grid"

However, when I run this code as part of the unchanged recorded macro, it does not auto-fit to contents. Anyone have any ideas where I went wrong?

I want it to autofit based on content, but the macro recorder won't record that part. I'm in ms word 2007. I've googled for 30 minutes but to no avail on what to do.

To auto-fit to the contents, I added the last line below:

WordBasic.TextToTable ConvertFrom:=1, NumColumns:=2, NumRows:=6, _
InitialColWidth:=wdAutoPosition, Format:=0, Apply:=1184, AutoFit:=1, _
SetDefault:=0, Word8:=0, Style:="Table Grid"
Selection.Tables(1).AutoFitBehavior wdAutoFitContent     ' *** Added this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM