473,772 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I save an HTML file with VBA?

Hi, I have access 97. I can upgrade if I have to (but that will cost
more money :)). If I want to read a row, parse that row, and then save
the values to an HTML file, will VBA do that?

Say I want to write:

<html>

<body>

<table>
<td>
row data from table
</td>
</table>

</body>

</html>

save results as .htm for that row, go to the next, save another .htm
file....

I'm not asking anyone to write this for me. I am only asking to be
pointed in the right direction. Thank you.

Mar 21 '06 #1
3 6128
Yes. HTML is simply particular characters saved in a text file, and there
are File I/O statements in VBA that read and write text files. Look in Help
for Open, Input#, Print#, and Close, as a start. These File I/O statements
have been around since DOS Basic.

Larry Linson
Microsoft Access MVP

<ne***********@ gmail.com> wrote in message
news:11******** *************@i 39g2000cwa.goog legroups.com...
Hi, I have access 97. I can upgrade if I have to (but that will cost
more money :)). If I want to read a row, parse that row, and then save
the values to an HTML file, will VBA do that?

Say I want to write:

<html>

<body>

<table>
<td>
row data from table
</td>
</table>

</body>

</html>

save results as .htm for that row, go to the next, save another .htm
file....

I'm not asking anyone to write this for me. I am only asking to be
pointed in the right direction. Thank you.

Mar 21 '06 #2

<ne***********@ gmail.com> wrote in message
news:11******** *************@i 39g2000cwa.goog legroups.com...
Hi, I have access 97. I can upgrade if I have to (but that will cost
more money :)). If I want to read a row, parse that row, and then save
the values to an HTML file, will VBA do that?

Say I want to write:

<html>

<body>

<table>
<td>
row data from table
</td>
</table>

</body>

</html>

save results as .htm for that row, go to the next, save another .htm
file....

I'm not asking anyone to write this for me. I am only asking to be
pointed in the right direction. Thank you.


I see you're not asking anyone to write it for you, but if you need to ask
whether it can be done, I'm guessing you might need a little help in getting
it done. Here is an example function which generates an html file for a
table of products. If you cut and paste the code below into a new module,
you will be able to call it like this:

If CreateProductHt ml("C:\Products .htm") Then
MsgBox "File Created",vbInfo rmation
End If
' *** Code Starts ***
Option Compare Database
Option Explicit

Public Function CreateProductHt ml(strPath As String) As Boolean

On Error GoTo Err_Handler

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim lngMaxField As Long
Dim lngCount As Long
Dim intFile As Integer
Dim strLine As String
Dim blnFileOpen As Boolean

intFile = FreeFile

If Len(Dir(strPath )) > 0 Then
If MsgBox("Overwri te existing file?" & vbCrLf & _
strPath, vbExclamation Or vbYesNoCancel) = vbYes Then
Kill strPath
Else
Exit Function
End If
End If

Open strPath For Output As #intFile

blnFileOpen = True

strSQL = "SELECT * FROM tblProduct ORDER BY ProductID"

Set dbs = CurrentDb()

Set rst = dbs.OpenRecords et(strSQL, dbOpenForwardOn ly, dbReadOnly)

If Not rst.EOF Then

lngMaxField = rst.Fields.Coun t - 1

Print #intFile, "<html>"
Print #intFile, "<head>"
Print #intFile, "<title>Pro duct List</title>"
Print #intFile, "</head>"
Print #intFile, "<body>"
Print #intFile, "<table border=2>"
While Not rst.EOF
Print #intFile, "<tr>"
For lngCount = 0 To lngMaxField
strLine = Trim(Nz(rst.Fie lds(lngCount).V alue, ""))
If Len(strLine) = 0 Then
strLine = "&nbsp;"
End If
strLine = "<td>" & strLine & "</td>"
Print #intFile, strLine
Next lngCount
Print #intFile, "</tr>"
rst.MoveNext
Wend
Print #intFile, "</table>"
Print #intFile, "</body>"
Print #intFile, "</html>"

CreateProductHt ml = True

End If

Exit_Handler:

If blnFileOpen Then
Close #intFile
End If

If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If

If Not dbs Is Nothing Then
Set dbs = Nothing
End If

Exit Function

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Function
' *** Code Ends ***
Mar 21 '06 #3
clovisthefrog
1 New Member
thanks this is really useful

<needin4mation@ gmail.com> wrote in message
news:1142917024 .767270.57120@i 39g2000cwa.goog legroups.com...[color=blue]
> Hi, I have access 97. I can upgrade if I have to (but that will cost
> more money :)). If I want to read a row, parse that row, and then save
> the values to an HTML file, will VBA do that?
>
> Say I want to write:
>
> <html>
>
> <body>
>
> <table>
> <td>
> row data from table
> </td>
> </table>
>
> </body>
>
> </html>
>
> save results as .htm for that row, go to the next, save another .htm
> file....
>
> I'm not asking anyone to write this for me. I am only asking to be
> pointed in the right direction. Thank you.[/color]



I see you're not asking anyone to write it for you, but if you need to ask
whether it can be done, I'm guessing you might need a little help in getting
it done. Here is an example function which generates an html file for a
table of products. If you cut and paste the code below into a new module,
you will be able to call it like this:

If CreateProductHt ml("C:\Products .htm") Then
MsgBox "File Created",vbInfo rmation
End If


' *** Code Starts ***
Option Compare Database
Option Explicit

Public Function CreateProductHt ml(strPath As String) As Boolean

On Error GoTo Err_Handler

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim lngMaxField As Long
Dim lngCount As Long
Dim intFile As Integer
Dim strLine As String
Dim blnFileOpen As Boolean

intFile = FreeFile

If Len(Dir(strPath )) > 0 Then
If MsgBox("Overwri te existing file?" & vbCrLf & _
strPath, vbExclamation Or vbYesNoCancel) = vbYes Then
Kill strPath
Else
Exit Function
End If
End If

Open strPath For Output As #intFile

blnFileOpen = True

strSQL = "SELECT * FROM tblProduct ORDER BY ProductID"

Set dbs = CurrentDb()

Set rst = dbs.OpenRecords et(strSQL, dbOpenForwardOn ly, dbReadOnly)

If Not rst.EOF Then

lngMaxField = rst.Fields.Coun t - 1

Print #intFile, "<html>"
Print #intFile, "<head>"
Print #intFile, "<title>Pro duct List</title>"
Print #intFile, "</head>"
Print #intFile, "<body>"
Print #intFile, "<table border=2>"
While Not rst.EOF
Print #intFile, "<tr>"
For lngCount = 0 To lngMaxField
strLine = Trim(Nz(rst.Fie lds(lngCount).V alue, ""))
If Len(strLine) = 0 Then
strLine = "&nbsp;"
End If
strLine = "<td>" & strLine & "</td>"
Print #intFile, strLine
Next lngCount
Print #intFile, "</tr>"
rst.MoveNext
Wend
Print #intFile, "</table>"
Print #intFile, "</body>"
Print #intFile, "</html>"

CreateProductHt ml = True

End If

Exit_Handler:

If blnFileOpen Then
Close #intFile
End If

If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If

If Not dbs Is Nothing Then
Set dbs = Nothing
End If

Exit Function

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Function
' *** Code Ends ***
May 4 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11635
by: 00steve | last post by:
Hi, I was wondering if anyone knew how to go about having a "save as HTML" option incorporated within a page. (I know the option is available from the file menu from within IE, but a client has requested that a button be used instead) Does anyone know how to go about accomplishing this? The possibility of IE specific code is available, as IE 6 is assumed as the client. Thanks in advance.
10
15617
by: Prakashsir | last post by:
I have desgined script to show div at runtime. Now I want to copy that newly created div and/or to save in normal html file so that i can see later. 1. When I select all the content or view its source, it does not shows the newly created div. 2. My script is working in IE but not working in Mozilla firefox. (I want to work in Mozilla, b'cause when we select all the content with new div and can save with that also.) 3. I want to save...
1
335
by: J. Koskey | last post by:
Background: We have hundreds of codes = specific departments, but there are frequent changes/additions to the info. For users to look up definitions, we had set up a way in Access to create a webpage link for each separate code. Back in an earlier version of Access - 97 or possibly 95 - there was a command of <File><Save as HTML> which let us select *all* of the 350+ queries and go through a wizard to save them all as HTML. Problem:...
0
6437
by: a | last post by:
Save text file as html kloepper 17:42 23 Jul '04 I'm using httpwebresponse and a StringBuilder to return a stream that originates as a file with the .txt suffix (My download code converts the html tags in this text file to well formed XHTML tags). The contents of the file contain html tags and the data in those tags. eg., <table cellSpacing=0 cellPadding=0 width="100%" align=center border=0> <TBODY> <tr> <td width="48%"></td> <td...
4
4532
by: Jae | last post by:
I'm writing a web application that exports and imports excel files. The application gets a list of users and their info and displays it in a datagrid .The user then selects to save the file as a tab delimited file or an excel file. The application then saves the file in the correct format. The flip side is for the user to import/upload the file to the server The application must be able to import the excel file and read the contents. I...
4
3719
by: Glenn M | last post by:
I have a shared XML file on a server . i also have one xslt file that performs a simple transform on in to view the data. now i want to have another page that lets users modify the shared xml file via some editable controls such as text boxes , option boxes etc. how can i implment this , should i use another xslt file with <INPUT> controls . if so how can i save the result back using the asp.net
3
2553
by: B-Dog | last post by:
I'm checking some files to see if the filenames are in a certain format and if not I want to pull up a dialog box that gives me a save as with the file that is in question. I have all the files in a certain directory and if it doesn't meet my criteria then I want to do a "save as" to a different location. How can I do that. I can't seem to get the save as dialog to grab the filename of the file in question and ask for a place to save it....
3
8563
by: fiefie.niles | last post by:
I would like to save a web page to a file and have the hyperlinks work when I bring the file back up. If the web page has a hyperlink like the following <a href="OurWeb/News/abcFile.htm">, after saving the file and showing it on the screen, and you try to click on the link, it will try to go to C:\OurWeb\News\abcFile.htm instead of www.MyWebSite.com/OurWeb/News/abcFile.htm. If I am on the website www.MyWebSite.com, and do "File" - "Save...
1
4884
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop program,which can upload many file in folder.problem is,am unable to save my file name in to database.because i used same name for all input file type as file. i dont know get name of file.below i presented my coding for ur view.fed up with my coding..pls...
0
9619
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9911
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.