G
Guest
Hi, I've been searching for a solution to the following problem for more than a week. I've posted it here a couple of times, and got some good ideas, but unfortunately they did not work. The variable "myfolder1" has the correct value, followed by ".xls" as it should.
I'd be very thankful if someone could find my error. This is the original question:
I am new to Exel, and i cannot find my error in the following script.
The error is:
Run time erroro '9'
Subscript out of range
and it always stops on the "windows(my folder1).activate" line
My goal it to be able to rename a file using a cell content, and still be able to run this macro. I'm putting the cell content into a variable, the variable is set to the correct value, but I still get the error.
Below is an exact copy/paste. I suspect there is a syntax error. If anyone can you see what I am doing wrong, please let me know.
Thanks
Sub List_Req2()
Dim myfolder1 As String
Range("A3").Select
Selection.Copy
Range("G3").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
With ThisWorkbook
myfolder1 = .Worksheets("hotline").Range("G3").Value & ".xls"
Range("F19").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("A1").Select
Windows(myfolder1).Activate
' ABOVE IS THE LINE IT STOPS ON
Sheets("Request for Service").Select
Range("I13:J13").Select
Selection.Copy
Windows("list_Req.xls").Activate
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("A1").Select
Windows(myfolder1).Activate
Application.CutCopyMode = False
Sheets("Hotline").Select
Range("G3").Select
Selection.ClearContents
End With
End Sub
I'd be very thankful if someone could find my error. This is the original question:
I am new to Exel, and i cannot find my error in the following script.
The error is:
Run time erroro '9'
Subscript out of range
and it always stops on the "windows(my folder1).activate" line
My goal it to be able to rename a file using a cell content, and still be able to run this macro. I'm putting the cell content into a variable, the variable is set to the correct value, but I still get the error.
Below is an exact copy/paste. I suspect there is a syntax error. If anyone can you see what I am doing wrong, please let me know.
Thanks
Sub List_Req2()
Dim myfolder1 As String
Range("A3").Select
Selection.Copy
Range("G3").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
With ThisWorkbook
myfolder1 = .Worksheets("hotline").Range("G3").Value & ".xls"
Range("F19").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("A1").Select
Windows(myfolder1).Activate
' ABOVE IS THE LINE IT STOPS ON
Sheets("Request for Service").Select
Range("I13:J13").Select
Selection.Copy
Windows("list_Req.xls").Activate
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("A1").Select
Windows(myfolder1).Activate
Application.CutCopyMode = False
Sheets("Hotline").Select
Range("G3").Select
Selection.ClearContents
End With
End Sub