Specify dataSource of Table as an array of data. To display a collection of structured data. Fixed header and scroll bar with the pageĪ table displays rows of data.Sub DeleteAllHeadersFooters(doc As Document) Sub MyMacro(flpath As String, fl As String) If Right(flpath, 1) Application.PathSeparator Then flpath = flpath & Application.PathSeparator Word VBA Macro Sub RunMacroOnAllFilesInFolder()įlpath = InputBox("Please enter the path to the folder you want to run the macro on.") I'm guessing that it's maybe because the original table in the original word document contains merged cells, otherwise why would the script not work on columns 4-7?Īny help would be greatly appreciated. When you select the option, Word clears the Preferred. What's going on here? Why isn't SetTableWidths working as expected? Table Tools Layout > AutoFit > Fixed Column Width gives you control over column widths. Step 1 Click a column where you want to add an additional column and then click. I tested the macro on another file I created, where I inserted 3 tables.įigure 4 (above): I created a new file with 3 tables, all with different column widths.įigure 5 (above): Running the macro with this test file in the same folder as the example document previously, shows that the macro works, and adjusts the columns in all tables to the specified width. The following steps will help you add columns in a table of a Word document. However, if you dont fix the cells height and turn off the automatically resize to fit. When you put a picture into a table cell via Insertpicture, Words default behaviour is to autofit the pictures to the cell size. Tables get pushed beyond the right-margin or a single line widens a column unnecesarily. AutoFit for Word tables is great but sometimes gets too enthusiastic. Sometimes you don’t want this and want to be able to control the column widths yourself. Here's a link to the original document: Testing on another file There is a vast amount of information about Word vba on the web, the great majority of which is applicable to Word 2010. Word will automatically adjust or Autofit the width of table columns and the space within cells to fit the content that you are entering. You can see that only the first 3 columns are adjusted, but columns 4-7 are unmodified.įigure 3 (above): This is what I expected the table to look like after running my macro to set all columns to 1.5 inches in width. In this example, I ran the macro to set all column widths to 1.5 ( InchesToPoints(1.5)). Illustrating the problem with screenshotsįigure 1 (above): This is what the original table looks like in the Word document.įigure 2 (above): This is what the table looks like after running my macro. It only works, in the example document shown here, on the first 3 columns. To fit the columns to the text (or page margins if cells are empty), click AutoFit > select 'AutoFit. In 'Table Tools' click the Layout tab > locate the 'Cell Size' group and choose from of the following options: To fit. However, when my script attempts to set all the columns in the document's tables to the same width, this doesn't work. To adjust table row and column size in Word: Click anywhere in the table. Click on OK to close the Table Properties dialog box. Repeat steps 5 and 6 until you have set all the column widths desired. Use the Previous Column or Next Column buttons, as desired, to select other columns. Using the Preferred Width control, set the column width as desired. docx files in a folder, based on a user-prompted file path. The Column tab of the Table Properties dialog box. I've got a Word VBA macro that runs a script (below) over all. I want to make all the table column widths identical at 2 inches, so I can subsequently save all the files as PDF, and prepare them for use in another process which I will not elaborate on. However, the column widths are not always the same. Manually resizing columns overrides Size Columns to Fit. Every document contains a table of identical layout (some of the documents span across 2 pages). To manually resize columns, click the right border of the column header and drag it left or right. To fit the table to the text, click AutoFit. I have a folder with 84 Word documents (.docx). To fit the columns to the text (or page margins if cells are empty), click AutoFit > select AutoFit Contents.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |