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, "OCA") 'column and row headings with shading
MsgBox "Xl2HTMLx ended"
End Sub
Sub XL2HTML()
Call XL2HTML_Main(0, "OCA") 'default no column nor row headings
End Sub
Sub XL2HTMLa()
'David McRitchie 2003-02-09 Separate Areas based on marksepareas
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim i As Long, optFile As String
Dim mareas As Range
Set mareas = Selection
MsgBox mareas.Address(0, 0)
For i = 1 To mareas.Areas.Count
mareas.Areas(i).Select
optFile = ""
If i = 1 Then optFile = "O" 'letter o
If i = mareas.Areas.Count Then optFile = optFile & "C"
Call XL2HTML_Main(1, optFile & "A") '0 no shading /1 shaded headers
Next i
mareas.Select
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
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, A=Align space
'Original coding and concept is based 28 lines of codeon
'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
'rev. 2003-02-09 multiple areas (snake cols) see xl2HTMLa
' prob. not compatible with multiple sheets
'rev. 2003-09-06 TR align/bgcolor
'rev. 2003-09-07 Extra space for cells with A160, fix yesterday's alignment
'Planning -- revision possibilities:
' -- think everything that had been listed here was done
' -- styles
' -- Conditional formatting interior colors could be added
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, xx As String
Dim A160 As String
If InStr(opt2, "A") Then A160 = Chr(160) 'force left/rt space
Dim shadehd As String:
shadehd = " bgcolor=""#d8d8d8"""
Dim i As Long, iPos As Long
Dim newx As String
Dim arrColor(0 To 2, 0 To 256) As String
Dim arrAlign(0 To 256) As String
Dim arrColorI(0 To 256) As String
Dim ArrColorF(0 To 256) 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(Selection.Cells(1, c).AddressLocal(0, 0)) - 1) & " | " Next c x = x & "
" _ & xx & (Selection.Cells(r, 1).Row) & " | " End If 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, "