Simple? Modify Macro: Add date in Column "C" to local filename

jeffcoleky

Active Member
Joined
May 24, 2011
Messages
274
Code:
Dim URL As StringDim LocalFileName As String
Dim B As Boolean
Dim ErrorText As String
Dim C As Range
Dim sTxt As String
sTxt = Cells(1, "a").Value
Dim Lastrow As Long
    
Lastrow = Range("C:D").Find("*", , , , xlByRows, xlPrevious).Row
For Each C In Range("C1:D" & Lastrow)
    If Len(C) > 0 Then
        URL = C.Text
[B]          LocalFileName = "C:\temp\" & Range("A" & C.Row) & " " & Range("A" & C.Row) & " " & Evaluate("TRIM(RIGHT(SUBSTITUTE(""" & C.Text & """,""/"",REPT("" "",1000)),1000))")[/B]

        B = DownloadFile(UrlFileName:=URL, _
                         DestinationFileName:=LocalFileName, _
                         Overwrite:=DoNotOverwrite, _
                         ErrorText:=ErrorText)
        If B = True Then
            Debug.Print "Download successful"
        Else
            Debug.Print "Download unsuccessful: " & ErrorText
        End If
    End If
Next C


End Sub

Currently, this code does not include the data in column C in the local filename. However, I would like it to. The dates in column C are formatted as "mm'dd/yyyy" but I'm OK with the local filename formatted as "mmddyyy" or "mm-dd-yyyy".

Can anyone help me update the code above to include the date value in column C for each line?
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I don't know why you have column A twice, but does this work for you?

Code:
LocalFileName = "C:\temp\" & Range("A" & C.Row) & " " & Range("A" & C.Row) & " " & Format(C.Value, "mmddyyyy")
 
Upvote 0
COLUMN A, Then COLUMN B, Then the formula already in the code "Evaluate("TRIM(RIGHT(SUBSTITUTE(""" & C.Text & """,""/"",REPT("" "",1000)),1000))")"
 
Upvote 0
do you mind writing it out for me? I'm dancing in circles trying to figure this simple step out. One of those days.
 
Upvote 0
Is it?

Rich (BB code):
LocalFileName = "C:\temp\" & Range("A" & C.Row) & " " & Format(Range("B" & C.Row), "mmddyyyy") & " " & Evaluate("TRIM(RIGHT(SUBSTITUTE(""" & C.Text & """,""/"",REPT("" "",1000)),1000))")
 
Upvote 0
Is it?

Rich (BB code):
LocalFileName = "C:\temp\" & Range("A" & C.Row) & " " & Format(Range("B" & C.Row), "mmddyyyy") & " " & Evaluate("TRIM(RIGHT(SUBSTITUTE(""" & C.Text & """,""/"",REPT("" "",1000)),1000))")

Worked great! exactly what needed! Thanks
 
Upvote 0

Forum statistics

Threads
1,214,400
Messages
6,119,292
Members
448,885
Latest member
LokiSonic

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top