'Attribute VB_Name = "McRitchie_HTML"
'Attribute VB_Description = "HTML conversion"
'--- remove this and above lines to install -------
Option Explicit
Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal _
lpOperation As String, ByVal lpFile As _
String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal _
nShowCmd As Long) As Long
Declare Function GetForegroundWindow Lib "user32" () As Long
Public filename As String
'Omitted here because it is also in McRitchie_BuildTOC
' Sub DelHyperLinks()
' 'David McRitchie
' Selection.Hyperlinks.Delete
' End Sub
Sub spintest201()
Dim cell As Range 'just testing
For Each cell In Selection
cell.Value = cell.MergeArea.Cells(1).Address _
& " " & cell.MergeArea.Columns.Count _
& " " & cell.MergeArea.Rows.Count
Next cell
End Sub
Sub spintest202()
Dim c As Long, r As Long
For r = 1 To Selection.Rows.Count
For c = 1 To Selection.Columns.Count
If Selection.Cells(r, c).Address = Selection.Cells(r, c).MergeArea.Cells(1).Address Then
Selection.Cells(r, c).Value = Selection.Cells(r, c).MergeArea.Cells(1).Address _
& " -- " & Selection.Cells(r, c).MergeArea.Columns.Count _
& " " & Selection.Cells(r, c).MergeArea.Rows.Count _
& " " & Selection.Cells(r, c).HorizontalAlignment
End If
Next c
Next r
End Sub
'DelHyperLinks, delete hyperlinks for selection
' suggested use on email addresses, if converting to HTML
'XL2HTML, Convert selection to HTML
'XL2HTMLx, Convert selection to HTML with row/column headers
' does not yet include color changes, etc.
Sub XL2HTMLx()
Call [personal.xls].XL2HTML_Main(1, "OC") 'column and row headings with shading
MsgBox "Xl2HTMLx ended"
End Sub
Sub XL2HTML()
Call XL2HTML_Main(0, "OC") 'default no column nor row headings
End Sub
Sub XL2HTMLs()
'Example: output multiple selected sheets...
Dim optFile As String
Dim shtCnt As Long
Dim mshtCnt As Long
Dim sht As Variant
shtCnt = 0
mshtCnt = Application.ActiveWorkbook.Windows(1).SelectedSheets.Count
For Each sht In Application.ActiveWorkbook.Windows(1).SelectedSheets
Sheets(sht.Name).Select
shtCnt = shtCnt + 1
optFile = ""
If shtCnt = 1 Then optFile = "O" 'letter o
If shtCnt = mshtCnt Then optFile = optFile & "C"
Cells.Select
Call XL2HTML_Main(0, optFile)
Next sht
End Sub
Sub XL2HTML_Main(Optional shading As Long, _
Optional opt2 As String, _
Optional optOutputFile As String)
'O=open,C=Close,""=default, 1=special, T=Time
'Original coding and concept is based on
'http://www.herber.de/mailing/020598v.txt
' Hans W. Herber * Microsoft Excel MVP
'Major changes D.McRitchie, 1998-08- msgbox, close,
' http://www.mvps.org/dmcritchie/excel/xl2htmlx.txt
' Shading option, Column & ROW headings and will use center justification
' when specifically formatted into Excel.
'Additional help Invoking IExplorer from VBA -
' From: "Chris Rae" posted Excel.programming 9Jun1999
'rev. 2000-06-25, hyperlinks for http:// (not email)
' Include Bold, Italic, Color (black for email)
'rev. 2000-07-01, handle merged cells (Rob Bruce),
' additional changes: center justification,
' multiple cells with TR "line", if fits in 80 bytes,
' XL2HTML_Main will be used by both XL2HTML and XL2HTMLx,
' center justification. Rev. 2000-07-02 added
for Chr(10)
'rev. 2000-07-03 for Center Across Selection (cell format)
'rev. 2001-08-11 multiple sheets, entire used content from each
'rev. 2001-08-11 for optional output dataset name in parameters
'rev. 2002-07-25 to right align numbers by default
'rev. 2002-08-24 to not right align empty cells
Dim r%, c%
Dim nr As Long, nC As Long
Dim lastcell As Range
'Dim xtra As Long
'Dim filename As Variant
'Dim shadehd As Variant
Dim retval As Variant
Dim x As String
Dim shadehd As String:
shadehd = " bgcolor=""#d8d8d8"""
Dim i As Long, iPos As Long
Dim newx As String
'Worksheets(1).Select
nr = Selection.Rows.Count
nC = Selection.Columns.Count
Set lastcell = Cells.SpecialCells(xlLastCell)
If nr > lastcell.Row Then nr = lastcell.Row
If nC > lastcell.Column Then nC = lastcell.Column
'iRows = Selection.Rows.Count
'iColumns = Selection.Columns.Count
'To Be Added: radio buttons, Row hdr, Col hdr, Shade hdr
' include suggested filename of c:\temp\XL2test.htm
'(I include that file in my browsers bookmarks/favorites)
filename = "c:\temp\XL2test.htm"
If optOutputFile <> "" Then filename = optOutputFile
If InStr(opt2, "O") Then
filename = InputBox("Supply filename for HTML generated from " _
& "selected range", "Filename for XL2HTML", filename)
End If
If InStr(opt2, "O") Or InStr(opt2, "1") Then
Close #1
Open filename For Output As 1
End If
If InStr(opt2, "O") Then
Print #1, "
  | " For c = 1 To nC x = x & "" & Left(Selection.Cells(1, c).AddressLocal(0, 0), _ Len(Cells(1, c).AddressLocal(0, 0)) - 1) & " | " Next c x = x & "
" & (Selection.Cells(r, 1).Row) & " | " For c = 1 To nC CenterAC = 0 'watch for Center Across Selection (Columns) 'numbers and text must be right aligned when generating HTML here If Selection.Cells(r, c).Address = _ Selection.Cells(r, c).MergeArea.Cells(1).Address Then '** secondary merged cells will not be processed ** TD = "td" 'No special support for THEAD '|
... | |
---|---|
... |
" End If End Sub Sub pix() Dim MyFile, MyPath, MyName, filename, MyFile_Str As String MyFile_Str = InputBox("Provide directory with .jpg files" & Chr(10) _ & "for generating the SRC in ", _ "PIX: create HTML file for quick viewing", _ "c:\my documents\fdm_DC3200_pict\2001c\*.jpg") If MyFile_Str = "" Then Exit Sub filename = InputBox("provide full filename for output HTML file", _ "PIX: output file for create HTML File for quick viewing", _ "c:\temp\pix.htm") If MyFile_Str = "" Then Exit Sub MyFile = Dir(MyFile_Str, vbDirectory) Close #1 Open filename For Output As 1 Print #1, "
" Print #1, "" more: Print #1, " " MyFile = Dir If MyFile <> "" Then GoTo more Print #1, "" Close #1 Shell "notepad " & filename 'ShellExecute 0, "open", filename, "", "", 0 End Sub Sub XL2HTMLQ() 'O=open,C=Close,""=default, 1=special, T=Time 'Based on ... ' http://www.mvps.org/dmcritchie/excel/xl2htmlx.txt Dim r%, c% Dim nr As Long, nC As Long Dim lastcell As Range Dim retval As Variant Dim i As Long, iPos As Long Dim newx As String Dim optOutputFile As String Dim opt2 As String Dim trStr As String Dim x As String opt2 = "O" 'Worksheets(1).Select nr = Selection.Rows.Count nC = Selection.Columns.Count Set lastcell = Cells.SpecialCells(xlLastCell) If nr > lastcell.Row Then nr = lastcell.Row If nC > lastcell.Column Then nC = lastcell.Column filename = "c:\temp\XL2test.htm" If optOutputFile <> "" Then filename = optOutputFile If InStr(opt2, "O") Then filename = InputBox("Supply filename for HTML generated from " _ & "selected range", "Filename for XL2HTML", filename) End If If InStr(opt2, "O") Or InStr(opt2, "1") Then Close #1 Open filename For Output As 1 End If If InStr(opt2, "O") Then Print #1, "" Print #1, "" End If Print #1, "" For r = 1 To nr trStr = "" For c = 1 To nC trStr = Selection.Cells(r, c).Text If Trim(trStr) = "" Then trStr = " " Next c Print #1, trStr Next r If InStr(opt2, "T") Then Print #1, "