I am STUCK!!
I have a sub that creates a filename from extracting parts of text from cells A1 and A2 on an imported workbook, then concatenating those values. My code is putting my filename on two lines of that cell; debug window shows it the same way. When this sub will be called by another Sub SaveFile(), Excel hits Runtime error 1004.
Here is what the target cell, and debug window, look like after the GetFileName sub runs:
Hot List
20171108
Here's my code:
Sub GetFileName
Dim ListName As String
Dim ListDate As Date
Dim TextDate
Dim MyString1
Dim MyString2
MyString1 = Worksheets("Stock List").Range("A1").Value
MyString2 = Worksheets("Stock List").Range("A2").Value
ListName = Right(MyString1, Len(MyString1) - InStr(MyString1, ": ") - 1)
ListDate = DateValue(Right(MyString2, Len(MyString2) - InStr(MyString2, "y, ") - 1))
Dim strMonth
Dim strDay
Dim strYear
strYear = Year(ListDate)
If Len(Month(ListDate)) = 1 Then
strMonth = "0" & Month(ListDate)
Else
strMonth = Month(ListDate)
End If
If Len(Day(ListDate)) = 1 Then
strDay = "0" & Day(ListDate)
Else
strDay = Day(ListDate)
End If
TextDate = strYear & strMonth & strDay
strFileName = ListName & " " & TextDate
Debug.Print strFileName
End Suber sub SaveFile(), I get Runtime error 1004.
Maybe someone can help me with this pesky issue. I cannot figure it out!
Thanks!
MIB
I have a sub that creates a filename from extracting parts of text from cells A1 and A2 on an imported workbook, then concatenating those values. My code is putting my filename on two lines of that cell; debug window shows it the same way. When this sub will be called by another Sub SaveFile(), Excel hits Runtime error 1004.
Here is what the target cell, and debug window, look like after the GetFileName sub runs:
Hot List
20171108
Here's my code:
Sub GetFileName
Dim ListName As String
Dim ListDate As Date
Dim TextDate
Dim MyString1
Dim MyString2
MyString1 = Worksheets("Stock List").Range("A1").Value
MyString2 = Worksheets("Stock List").Range("A2").Value
ListName = Right(MyString1, Len(MyString1) - InStr(MyString1, ": ") - 1)
ListDate = DateValue(Right(MyString2, Len(MyString2) - InStr(MyString2, "y, ") - 1))
Dim strMonth
Dim strDay
Dim strYear
strYear = Year(ListDate)
If Len(Month(ListDate)) = 1 Then
strMonth = "0" & Month(ListDate)
Else
strMonth = Month(ListDate)
End If
If Len(Day(ListDate)) = 1 Then
strDay = "0" & Day(ListDate)
Else
strDay = Day(ListDate)
End If
TextDate = strYear & strMonth & strDay
strFileName = ListName & " " & TextDate
Debug.Print strFileName
End Suber sub SaveFile(), I get Runtime error 1004.
Maybe someone can help me with this pesky issue. I cannot figure it out!
Thanks!
MIB