LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
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

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
download file of 200 name, addr.etc to excel file - how? please ad Tony V. Excel Worksheet Functions 1 October 24th 08 09:50 AM
HELP----Can't get a CSV file to download onto my PC Bubey New Users to Excel 2 June 8th 06 02:42 AM
How to write a micro to download file at a URL save the file at the local PC www.microsoft.com Excel Programming 2 March 9th 06 02:21 AM
I need to download an exel spreadsheet file. (file extension :xls) buckrogers Excel Discussion (Misc queries) 2 December 8th 04 11:08 PM
using vba to download file via ftp daryl Excel Programming 3 January 29th 04 07:58 AM


All times are GMT +1. The time now is 08:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"