I have a workbook with a button that launches a filedialog, after opening the new workbook I want to be able to run a set of macro immediately. The code that I use for opening the file is:
Sub openFile()
Dim SelectedFileItem As String
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogOpen)
With fDialog
'Custom dialog title
.Title = "Seleccione uno o varios archivos"
.AllowMultiSelect = False
'Set the file path
.InitialFileName = "C:\Users\Public"
'Filters for file types allowed
.Filters.Clear
.Filters.Add "Excel files", "*.xlsx"
If .Show = -1 Then
'if user clicks OK
SelectedFileItem = .SelectedItems(1)
'Open the selected file
Workbooks.Open (SelectedFileItem)
Else
'if user clicks Cancel
End If
End With
End Sub
and the set of macros I want to run immediately after selecting and opening the new workbook is:
Sub ReemplazarDotComma()
Dim ws_num As Integer
ws_num = ThisWorkbook.Worksheets.Count
Dim i As Integer
For i = 1 To ws_num
ThisWorkbook.Worksheets(i).Activate
Range("Y2:Y70").Select
ActiveWindow.SmallScroll Down:=-60
Selection.Replace What:=".", Replacement:=",", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Next
End Sub
Sub Convertir_Variant()
Dim ws_num As Integer
ws_num = ThisWorkbook.Worksheets.Count
Dim i As Integer
Dim j As Integer
For i = 1 To ws_num
ThisWorkbook.Worksheets(i).Activate
For j = 2 To 70
Cells(j, 25) = ConvertToVariant(Cells(j, 25))
Next
Next
End Sub