条件付き書式で現れた「結果」(セルが赤く塗られた,フォントの書式が変わった,など)を検索したり検出する方法は,..
マクロを使って出来なくもない..。(xl2003環境)
■VBA Replace(buf, "ignore:", "")で既出。scrap重ねですorz
ついでに
■RegisterClipboardFormatA("HTML Format")の使い回しでhttp://www.vbalab.net/vbaqa/c-board.cgi?cmd=one;no=70352;id=excel
マクロを使って出来なくもない..。(xl2003環境)
Option Explicit
'-----------------------------------------------------------
Sub prep() '準備。Bookを追加しSheet1のA1:A50に条件付き書式を設定。
With Workbooks.Add(xlWBATWorksheet).Sheets(1).Range("A1:A50")
.FormulaR1C1 = "=INT(RAND()*20)+1"
.Value = .Value
.FormatConditions.Add(Type:=xlCellValue, _
Operator:=xlBetween, _
Formula1:="5", _
Formula2:="10").Font.Color = vbRed
End With
End Sub
'-----------------------------------------------------------
Sub test() 'prep後BookをActiveにして実行。
Dim ws As Worksheet
Dim tmp As String
Dim buf As String
Dim n As Long
Dim r As Range
Application.ScreenUpdating = False
'作業用mhtファイル名を設定。 _
同名既存ファイルがあれば上書きするので注意。
tmp = Application.DefaultFilePath & "\temp.mht"
Set ws = ActiveSheet
ActiveWorkbook.PublishObjects.Add( _
xlSourceSheet, tmp, _
ws.Name, "", _
xlHtmlStatic).Publish True
'作業用mhtファイルOpen。
n = FreeFile
Open tmp For Input As #n
buf = StrConv(InputB(LOF(n), #n), vbUnicode)
Close #n
'---置換作業---
'途中改行があれば削除。
buf = Replace$(buf, "=" & vbCrLf, "")
'とにかく"ignore:"を消せばいいかな。
buf = Replace$(buf, "mso-ignore:", "")
'--------------
'作業ファイル書き込み直してOpen、検索作業。
n = FreeFile
Open tmp For Output As #n
Print #n, buf
Close #n
With Application.FindFormat
.Clear
.Font.Color = vbRed
End With
With Workbooks.Open(tmp)
With .Sheets(1).UsedRange
.Replace What:="*", _
Replacement:="#n/a", _
LookAt:=xlPart, _
SearchFormat:=True
On Error Resume Next
Set r = .SpecialCells(xlCellTypeConstants, xlErrors)
On Error GoTo 0
End With
If Not r Is Nothing Then
ws.Activate
ws.Range(r.Address(0, 0)).Select
End If
.Close False
End With
'作業用mhtファイル削除。
Kill tmp
Set r = Nothing
Set ws = Nothing
Application.ScreenUpdating = True
End Sub
'-----------------------------------------------------------
Sub prep() '準備。Bookを追加しSheet1のA1:A50に条件付き書式を設定。
With Workbooks.Add(xlWBATWorksheet).Sheets(1).Range("A1:A50")
.FormulaR1C1 = "=INT(RAND()*20)+1"
.Value = .Value
.FormatConditions.Add(Type:=xlCellValue, _
Operator:=xlBetween, _
Formula1:="5", _
Formula2:="10").Font.Color = vbRed
End With
End Sub
'-----------------------------------------------------------
Sub test() 'prep後BookをActiveにして実行。
Dim ws As Worksheet
Dim tmp As String
Dim buf As String
Dim n As Long
Dim r As Range
Application.ScreenUpdating = False
'作業用mhtファイル名を設定。 _
同名既存ファイルがあれば上書きするので注意。
tmp = Application.DefaultFilePath & "\temp.mht"
Set ws = ActiveSheet
ActiveWorkbook.PublishObjects.Add( _
xlSourceSheet, tmp, _
ws.Name, "", _
xlHtmlStatic).Publish True
'作業用mhtファイルOpen。
n = FreeFile
Open tmp For Input As #n
buf = StrConv(InputB(LOF(n), #n), vbUnicode)
Close #n
'---置換作業---
'途中改行があれば削除。
buf = Replace$(buf, "=" & vbCrLf, "")
'とにかく"ignore:"を消せばいいかな。
buf = Replace$(buf, "mso-ignore:", "")
'--------------
'作業ファイル書き込み直してOpen、検索作業。
n = FreeFile
Open tmp For Output As #n
Print #n, buf
Close #n
With Application.FindFormat
.Clear
.Font.Color = vbRed
End With
With Workbooks.Open(tmp)
With .Sheets(1).UsedRange
.Replace What:="*", _
Replacement:="#n/a", _
LookAt:=xlPart, _
SearchFormat:=True
On Error Resume Next
Set r = .SpecialCells(xlCellTypeConstants, xlErrors)
On Error GoTo 0
End With
If Not r Is Nothing Then
ws.Activate
ws.Range(r.Address(0, 0)).Select
End If
.Close False
End With
'作業用mhtファイル削除。
Kill tmp
Set r = Nothing
Set ws = Nothing
Application.ScreenUpdating = True
End Sub
■VBA Replace(buf, "ignore:", "")で既出。scrap重ねですorz
ついでに
■RegisterClipboardFormatA("HTML Format")の使い回しでhttp://www.vbalab.net/vbaqa/c-board.cgi?cmd=one;no=70352;id=excel