View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tim Armstrong[_6_] Tim Armstrong[_6_] is offline
external usenet poster
 
Posts: 1
Default How to download a .txt file...?


Hi!

How can I download a .TXT file and don't lose the formatting?
I found an example:

Code
-------------------

Option Explicit

Private Declare Function InternetGetConnectedState Lib "wininet" ( _
ByRef lpdwFlags As Long, _
ByVal dwReserved As Long) As Long

Private Declare Function InternetAutodial Lib "wininet.dll" ( _
ByVal dwFlags As Long, _
ByVal dwReserved As Long) As Long

Private Declare Function InternetAutodialHangup Lib "wininet.dll" ( _
ByVal dwReserved As Long) As Long


Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" ( _
ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long

'// Ie Constants
Private Const INTERNET_CONNECTION_CONFIGURED = &H40
Private Const INTERNET_CONNECTION_LAN = &H2
Private Const INTERNET_CONNECTION_MODEM = &H1
Private Const INTERNET_CONNECTION_OFFLINE = &H20
Private Const INTERNET_CONNECTION_PROXY = &H4
Private Const INTERNET_RAS_INSTALLED = &H10
Private Const INTERNET_AUTODIAL_FORCE_ONLINE = 1
Private Const INTERNET_AUTODIAL_FORCE_UNATTENDED = 2

Private Const S_OK = &H0
Private Const E_ABORT = &H80004004
Private Const E_ACCESSDENIED = &H80070005
Private Const E_OUTOFMEMORY = &H8007000E

'// Download File constants - Amend as required
Const strDwnLd_URLColo As String = _
"http://www.interq.or.jp/sun/puremis/colo/HtmlMaker2.32.zip"
Const strDest As String = "C:\HtmlMaker2.32.zip"

Sub GetHtmlFile()
Dim DwnLoadOK As Boolean

DwnLoadOK = DownloadFile(strDwnLd_URLColo, strDest)
If Not DwnLoadOK Then
MsgBox "Error downloading " & strDwnLd_URLColo & vbCr & IeState
Else
MsgBox "Succesfully downloaded:= " & strDest
End If

'// Lets Disconect now
On Error Resume Next
InternetAutodialHangup 0

End Sub

Public Function DownloadFile( _
URL As String, _
SaveAsFileName As String) As Boolean

Dim lngRetVal As Long
DownloadFile = False
'// Lets try downloading 1st by URL
'// If Not succesful then maybe settings
'// are on Manual connect?
'// so lets try forcing it !
InternetAutodial INTERNET_AUTODIAL_FORCE_UNATTENDED, 0
lngRetVal = URLDownloadToFile(0, URL, SaveAsFileName, 0, 0)
'//
If lngRetVal = 0 Then DownloadFile = True
End Function

Private Function IeState() As String
Dim Ret As Long
Dim Msg As String

'// Retrieve the connection status
InternetGetConnectedState Ret, 0&
'// show the result
If (Ret And INTERNET_CONNECTION_CONFIGURED) = _
INTERNET_CONNECTION_CONFIGURED Then _
Msg = "Local system has a valid connection to the Internet," & _
vbCr & "but it may or may not be currently connected."
If (Ret And INTERNET_CONNECTION_LAN) = _
INTERNET_CONNECTION_LAN Then _
Msg = Msg & vbCr & "Uses a local area network" & _
"to connect to the Internet."
If (Ret And INTERNET_CONNECTION_MODEM) = _
INTERNET_CONNECTION_MODEM Then _
Msg = Msg & vbCr & "A modem is used to connect to the Internet."
If (Ret And INTERNET_CONNECTION_OFFLINE) = _
INTERNET_CONNECTION_OFFLINE Then _
Msg = Msg & vbCr & "Local system is in offline mode."
If (Ret And INTERNET_CONNECTION_PROXY) = _
INTERNET_CONNECTION_PROXY Then _
Msg = Msg & vbCr & "Uses a proxy server to connect to the Internet."
If (Ret And INTERNET_RAS_INSTALLED) = INTERNET_RAS_INSTALLED Then _
Msg = Msg & vbCr & "System has RAS installed."

If Msg < "" Then IeState = Msg

End Function

-------------------

But this example lost the formating of .TXT file...

Thanks a lot for any help

--
Tim Armstron

-----------------------------------------------------------------------
Tim Armstrong's Profile: http://www.excelforum.com/member.php...fo&userid=3716
View this thread: http://www.excelforum.com/showthread.php?threadid=56937