|
#1
|
|||
|
|||
Word 2016 Multi-file Macro issues
I need to un-check 'prefered width' on table properties in hundreds of documents in the same folder. I'm a novice at Macros but made one I will share, It does not work and I need help finding out why. Any feedback is greatly appreciated.
Sub UpdateDocuments() Application.ScreenUpdating = False Dim strFolder As String, strFile As String, wdDoc As Document strFolder = GetFolder If strFolder = "" Then Exit Sub strFile = Dir(strFolder & "\*.docx", vbNormal) While strFile <> "" Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False) With wdDoc Dim pT As Word.Table For Each pT In ActiveDocument.Tables pT.PreferredWidth = Unchecked Next .Close SaveChanges:=True End With strFile = Dir() Wend Set wdDoc = Nothing Application.ScreenUpdating = True End Sub Function GetFolder() As String Dim oFolder As Object GetFolder = "" Set oFolder = CreateObject("Shell.Application").BrowseForFolder( 0, "Choose a folder", 0) If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.path Set oFolder = Nothing End Function Any amendments would be greatly appreciated. Thank you. |
#2
|
||||
|
||||
Preferred width is a cell property, so you need to apply it to the cells of the table, as below. I have not checked the rest of your code.
Code:
With wdDoc For Each pT In wdDoc.Tables pT.Range.Cells.PreferredWidthType = wdPreferredWidthAuto pT.Range.Cells.PreferredWidth = 0 Next End With
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
Tags |
macro, macro error, macro help |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Issues Using Power Query file in Excel 2016 and then in 2013 | bld9936 | Excel Programming | 0 | 02-27-2017 12:50 PM |
Word 2016 vs Word 2003 (issues I can't figure out) | AdventureCapitliast | Word | 6 | 02-23-2017 06:23 AM |
Multi page transfer of jpeg to word in OneNote 2016 | MikeEsq | OneNote | 0 | 12-25-2016 09:49 AM |
Document layout issues between Mac and Windows Word 2016 | tlj | Word | 2 | 12-16-2016 06:51 PM |
Word insert only 1st page of multi-paged PDF file | Evgeniy | Word | 1 | 02-04-2012 01:36 PM |