alainfranco
New Member
- Joined
- Mar 7, 2012
- Messages
- 38
Hello,
I am trying to set a variable that I can use throughout my macro. The variable is the filename with its associated path.
So far, Ive been succesfull in setting the variable and using it in certain objects, but not in others. The code is as follows:
Sub ScorecardImporter()
Dim SelectedFile As String
Dim ProjectClient As String
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False"
If .Show = -1 Then
SelectedFile = .SelectedItems(1)
Else
End If
End With
Workbooks.Open (SelectedFile)
Windows("SelectedFile").Activate
Worksheets("SelectedFile").Activate
Range("B3:C3").Select
Selection.Copy
.....
The variable works well with "Workbooks.Open (SelectedFile)", however I get an error with the Windows and Worksheets objects....
Would anyone have a clue as to why this is not working?
Any help would be appreciated,
Thanks!
I am trying to set a variable that I can use throughout my macro. The variable is the filename with its associated path.
So far, Ive been succesfull in setting the variable and using it in certain objects, but not in others. The code is as follows:
Sub ScorecardImporter()
Dim SelectedFile As String
Dim ProjectClient As String
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False"
If .Show = -1 Then
SelectedFile = .SelectedItems(1)
Else
End If
End With
Workbooks.Open (SelectedFile)
Windows("SelectedFile").Activate
Worksheets("SelectedFile").Activate
Range("B3:C3").Select
Selection.Copy
.....
The variable works well with "Workbooks.Open (SelectedFile)", however I get an error with the Windows and Worksheets objects....
Would anyone have a clue as to why this is not working?
Any help would be appreciated,
Thanks!