Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-08-2017, 10:46 AM
IneedHelpWithWord IneedHelpWithWord is offline Word 2016 Multi-file Macro issues Windows 10 Word 2016 Multi-file Macro issues Office 2016
Novice
Word 2016 Multi-file Macro issues
 
Join Date: Aug 2017
Posts: 1
IneedHelpWithWord is on a distinguished road
Exclamation 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.
Reply With Quote
  #2  
Old 08-08-2017, 09:29 PM
gmayor's Avatar
gmayor gmayor is offline Word 2016 Multi-file Macro issues Windows 10 Word 2016 Multi-file Macro issues Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
Reply

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 Multi-file Macro issues 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 2016 Multi-file Macro issues Word insert only 1st page of multi-paged PDF file Evgeniy Word 1 02-04-2012 01:36 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:56 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft