Message 1 of 5
Folder loop for dwg

Not applicable
08-19-2019
04:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hi,
I am trying to create a block extractor using VBA. As for the extractor code, I believe it's finished, but I need to apply it to different files. As such, I need to create a loop in a folder.
I looked around and found this great piece of code for looping .xlsx, but I can't make it work for .dwg files.
Sub AllWorkbooks() Dim MyFolder As String ‘Path collected from the folder picker dialog Dim MyFile As String ‘Filename obtained by DIR function Dim wbk As Workbook ‘Used to loop through each workbook On Error Resume Next Application.ScreenUpdating = False ‘Opens the folder picker dialog to allow user selection With Application.FileDialog(msoFileDialogFolderPicker) .Title = “Please select a folder” .Show .AllowMultiSelect = False If .SelectedItems.Count = 0 Then ‘If no folder is selected, abort MsgBox “You did not select a folder” Exit Sub End If MyFolder = .SelectedItems(1) & “\” ‘Assign selected folder to MyFolder End With myfile = Dir(MyFolder) ‘DIR gets the first file of the folder ‘Loop through all files in a folder until DIR cannot find anymore Do While myfile <> “” ‘Opens the file and assigns to the wbk variable for future use Set wbk = Workbooks.Open(Filename:=MyFolder & myfile) ‘Replace the line below with the statements you would want your macro to perform Sheets(2).Range(“a1”).Value = 60 wbk.Close savechanges:=True MyFile = Dir ‘DIR gets the next file in the folder Loop Application.ScreenUpdating = True End Sub
The code is very well explained by the creator, https://www.youtube.com/watch?v=J0PeXcAVaUM
Any help would be deeply appreciated 🙂