PDA

View Full Version : Macro Adjustment



jleve1974
01-30-2008, 01:14 PM
The code below basically just removes column A from all files within directory "C:\Documents and Settings\levanoj\Desktop\Lab1".
Can anyone adjust the code to instead prompt me to select a directory instead of just running it from the one noted?



Sub RemoveColumnA()
Dim myDir As String, fn As String
myDir = "C:\Documents and Settings\levanoj\Desktop\Lab 1"
fn = Dir(myDir & "\*.xls")
Do While fn <> ""
On Error Resume Next
With Workbooks.Open(myDir & "\" & fn)
.Sheets("Sheet1").Columns("a").Delete
.Close True
End With
fn = Dir()
Loop
MsgBox "Done!"
End Sub

Bob Phillips
01-30-2008, 01:29 PM
Sub RemoveColumnA()
Dim myDir As String, fn As String
Dim myDir As String
With Application.FileDialog(msoFileDialogFolderPicker)

.AllowMultiSelect = False
.Show

If .SelectedItems.Count > 0 Then

myDir = .SelectedItems(1)
fn = Dir(myDir & "\*.xls")
Do While fn <> ""

On Error Resume Next
With Workbooks.Open(myDir & "\" & fn)

.Sheets("Sheet1").Columns("a").Delete
.Close True
End With
fn = Dir()
Loop

MsgBox "Done!"
End If
End With
End Sub

jleve1974
01-30-2008, 02:14 PM
:rotlaugh: