dcsimg
Results 1 to 7 of 7

Thread: [RESOLVED] [Word] Macro Allow spacing between cells

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2019
    Posts
    3

    Resolved [RESOLVED] [Word] Macro Allow spacing between cells

    Hello, could You help me find a way to create macro that will be uchecking option „Allow spacing between cells” in Table Properties > Options menu - but in several tables in one document. (Recording macro doesn't work)
    Thank You for help in advance.

  2. #2
    Frenzied Member jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    1,328

    Re: [Word] Macro Allow spacing between cells


  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,140

    Re: [Word] Macro Allow spacing between cells

    i tested this, works ok
    Code:
    Dim t As Table
    For Each t In ActiveDocument.Tables
        t.Select
        With Dialogs(wdDialogTableTableOptions)
            .allowspacing = False
            .Execute
        End With
    Next
    Edit: this solution is version dependent, it will not work in office 2000, i do not know at which version that dialog becomes available to VBA
    Last edited by westconn1; Mar 9th, 2019 at 08:46 PM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2019
    Posts
    3

    Re: [Word] Macro Allow spacing between cells

    Hello,
    as a beginner in VBA I'm not sure, if I'm right, but according to "westconn1" the code doesn't work. To me it looks like it was something missing in it after command "Next". Please correct me if I'm wrong.
    The reference in the link also is not good in my situation.
    Meanwhile I've been thinking about different solution: transforming all tables to text divided with tabs, and then converting them again into tables. I've found a solution for changing table into text, but I cannot find a code to do the reverse. Could You help me in this problem?
    Here You have the code for converting table to text divided with tabulators:
    Code:
    Sub TablesToText()
    Dim tbl As Table
    For Each tbl In ActiveDocument.Tables
    tbl.ConvertToText
    Separator:=wdSeparateByTabs
    Next tbl
    Set tbl = Nothing
    End Sub

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,140

    Re: [Word] Macro Allow spacing between cells

    but according to "westconn1" the code doesn't work.
    i actually said i tested and it worked ok, but it is version dependant, at a guess i would assume that it will work in 2007 onwards, but as you are using a later version i would expect it to work correctly, i clarified mainly in case, that other may be reading this thread at a later time looking for a similar solution

    it was something missing in it after command "Next". Please correct me if I'm wrong.
    the entire code needs to be within a procedure if on its own end sub would be would be it, but it could be inserted into an existing procedure, that does other tasks, there is no need to set the table object to nothing after the for loop unless you have a conditional exit for

    you could build the range back into a table by code, but any added table would probably still have the same spacing between cells as any previous ones

    the testing i did was on a document with a very large table
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,140

    Re: [Word] Macro Allow spacing between cells

    but according to "westconn1" the code doesn't work.
    i actually said i tested and it worked ok, but it is version dependant, at a guess i would assume that it will work in 2007 onwards, but as you are using a later version i would expect it to work correctly, i clarified mainly in case, that other may be reading this thread at a later time looking for a similar solution

    it was something missing in it after command "Next". Please correct me if I'm wrong.
    the entire code needs to be within a procedure if on its own end sub would be would be it, but it could be inserted into an existing procedure, that does other tasks, there is no need to set the table object to nothing after the for loop unless you have a conditional exit for

    you could build the range back into a table by code, but any added table would probably still have the same spacing between cells as any previous ones

    the testing i did was on a document with a very large table and no problems
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    New Member
    Join Date
    Mar 2019
    Posts
    3

    Re: [Word] Macro Allow spacing between cells

    Tank You for a hint "westconn1"!
    As it occurred it was necessary for a beginner.
    Quote Originally Posted by westconn1 View Post
    the entire code needs to be within a procedure if on its own end sub would be would be it
    The final code that worked in my case was:
    Code:
    Sub CellSpacing()
    Dim t As Table
    For Each t In ActiveDocument.Tables
        t.Select
        With Dialogs(wdDialogTableTableOptions)
            .allowspacing = False
            .Execute
        End With
    Next
    End Sub

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width