aspiringnerd
New Member
- Joined
- Apr 22, 2022
- Messages
- 39
- Office Version
- 365
- Platform
- Windows
I'm getting an error when I change the sheet reference from this:
to this:
Sheet2 is hidden, I call this macro with a button on sheet1, it's only when I change sheet1 to sheet2 where I get error 1004, I'm not sure how to fix this one.
VBA Code:
Sub ExportHtml()
Dim ws As Worksheet, lr As Long, rng As Range
Set ws = Sheets("Sheets1")
lr = ws.Range("a" & ws.Rows.Count).End(xlUp).Row
Set rng = ws.Range("a1:h" & lr)
file1 = "C:\Desktop\" + Cells(ActiveCell.Row, "E").Value + ".html"
ActiveWorkbook.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=file1, _
Sheet:=rng.Worksheet.Name, _
Source:=rng.Address, _
HtmlType:=xlHtmlStatic).Publish
End Sub
to this:
VBA Code:
Sub ExportHtml()
Dim ws As Worksheet, lr As Long, rng As Range
Set ws = Sheets("Sheets2")
lr = ws.Range("a" & ws.Rows.Count).End(xlUp).Row
Set rng = ws.Range("a1:h" & lr)
file1 = "C:\Desktop\" + Cells(ActiveCell.Row, "E").Value + ".html"
ActiveWorkbook.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=file1, _
Sheet:=rng.Worksheet.Name, _
Source:=rng.Address, _
HtmlType:=xlHtmlStatic).Publish
End Sub
Sheet2 is hidden, I call this macro with a button on sheet1, it's only when I change sheet1 to sheet2 where I get error 1004, I'm not sure how to fix this one.