I am trying to download excel file from Google drive using vba code. The file gets downloaded in this path C:/MyDownloads/seriall.xlsx. But some weird text gets added on top of the downloaded excel file in the first sheet. And i also get a popup message with a message that the file you are trying to open is in a different format than specified. So I click yes to go through this popup and then I get a css file missing error popup. Why does this happen and why these errors appear in my downloaded excel file. My data is also shown at the bottom of weird text that excel adds on its on.
Dim FileNum As Long
Dim FileData() As Byte
Dim MyFile As String
Dim WHTTP As Object
On Error Resume Next
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5")
If Err.Number <> 0 Then
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
End If
On Error GoTo 0
MyFile = "https://docs.google.com/spreadsheets/d/1e6DNpw3y5NrMR9cNLmIZdPYO79WLui7mua5I-5pEyKo/edit?usp=sharing"
WHTTP.Open "GET", MyFile, False
WHTTP.send
FileData = WHTTP.ResponseBody
Set WHTTP = Nothing
If Dir("C:\Downloads", vbDirectory) = Empty Then MkDir "C:\Downloads"
FileNum = FreeFile
Open "C:\Downloads\serial.xls" For Binary As #FileNum
Put #FileNum, 1, FileData
Close #FileNum
MsgBox "Open the folder [ C:\Downloads ] for the "