<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Excel VBA Save As PDF: Step-By-Step Guide And 10 Code Examples To Export Excel To PDF	</title>
	<atom:link href="https://powerspreadsheets.com/save-excel-file-pdf-vba/feed/" rel="self" type="application/rss+xml" />
	<link>https://powerspreadsheets.com/save-excel-file-pdf-vba/</link>
	<description>Excel and VBA tutorials and training. Learn how to use Microsoft Excel and Visual Basic for Applications now.</description>
	<lastBuildDate>Mon, 08 May 2023 19:54:26 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>
		By: lydem12		</title>
		<link>https://powerspreadsheets.com/save-excel-file-pdf-vba/#comment-515</link>

		<dc:creator><![CDATA[lydem12]]></dc:creator>
		<pubDate>Mon, 08 May 2023 19:54:26 +0000</pubDate>
		<guid isPermaLink="false">https://powerspreadsheets.com/?p=5051#comment-515</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://powerspreadsheets.com/save-excel-file-pdf-vba/#comment-392&quot;&gt;David&lt;/a&gt;.

&lt;p&gt;Bonjour ce tuto a été très enrichissant et je vous suis très reconnaissant. &lt;/p&gt;&lt;p&gt;Fin de la sous-section&lt;/p&gt;&lt;p&gt;&#160;&#160;Dim wb As Workbook, feuille As Worksheet&lt;/p&gt;&lt;p&gt;&#160;&#160;Dim plage As String, nomDocument As String, dossierAdresse As String&lt;/p&gt;&lt;p&gt;&#160;&#160;Dim iVis As XlSheetVisibility&lt;/p&gt;
&lt;p&gt; Définir wb = ThisWorkbook&lt;/p&gt;&lt;p&gt; Set feuille = wb. Feuilles(«&#160;Devis&#160;»)&lt;/p&gt;&lt;p&gt; dossierAdresse = Sheets(«&#160;Paramètres&#160;»). Gamme(«&#160;K9&#160;»). Valeur &#038; «&#160;\&#160;»&lt;/p&gt;&lt;p&gt; nomDocument = feuille. Gamme(«&#160;J10&#160;»). Valeur&lt;/p&gt;
&lt;p&gt;&#160;&#160;&#039;Mettre à plage l adresse de la plage à imprimer&lt;/p&gt;&lt;p&gt; plage = «&#160;$C$6:$M$53&#160;» &lt;/p&gt;
&lt;p&gt;&#160;&#160;Application.ScreenUpdating = False&lt;/p&gt;
&lt;p&gt; Avec feuille. PageSetup&lt;/p&gt;&lt;p&gt; . PrintArea = plage&lt;/p&gt;&lt;p&gt; . FitToPagesTall = 1&lt;/p&gt;&lt;p&gt; . FitToPagesWide = 1&#039; Définissez FitToPagesWide sur 1&lt;/p&gt;&lt;p&gt; . LeftMargin = Application.InchesToPoints(0)&lt;/p&gt;&lt;p&gt; . RightMargin = Application.InchesToPoints(0)&lt;/p&gt;&lt;p&gt; . TopMargin = Application.InchesToPoints(0)&lt;/p&gt;&lt;p&gt; . BottomMargin = Application.InchesToPoints(0)&lt;/p&gt;&lt;p&gt; Terminez par&lt;/p&gt;

&lt;p&gt; Avec feuille&lt;/p&gt;&lt;p&gt; iVis = . Visible&lt;/p&gt;&lt;p&gt; . Visible = xlSheetVisible&lt;/p&gt;&lt;blockquote&gt;&lt;strong&gt;&lt;em&gt; . Activer&lt;/em&gt;&lt;/strong&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt; . Type ExportAsFixedFormat :=xlTypePDF, _&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt; Nom de fichier:=dossierAdresse &#038; nomDocument &#038; «&#160;.pdf&#160;», _&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Quality:=xlQualityStandard, IncludeDocProperties:=True, _&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;strong&gt;&lt;em&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;IgnorePrintAreas:=False, OpenAfterPublish:=True&lt;/em&gt;&lt;/strong&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;br&gt;&lt;/blockquote&gt;&lt;p&gt; . Visible = iVis&lt;/p&gt;&lt;p&gt; Terminez par&lt;/p&gt;
&lt;p&gt; Application.ScreenUpdating = Vrai&lt;/p&gt;
&lt;p&gt;Fin de la sous-section&lt;/p&gt;&lt;p&gt;Je vous prie de m’aider a trouver une correction a la partie entre guillemets. Merci&lt;/p&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://powerspreadsheets.com/save-excel-file-pdf-vba/#comment-392">David</a>.</p>
<p>Bonjour ce tuto a été très enrichissant et je vous suis très reconnaissant. </p>
<p>Fin de la sous-section</p>
<p>&nbsp;&nbsp;Dim wb As Workbook, feuille As Worksheet</p>
<p>&nbsp;&nbsp;Dim plage As String, nomDocument As String, dossierAdresse As String</p>
<p>&nbsp;&nbsp;Dim iVis As XlSheetVisibility</p>
<p> Définir wb = ThisWorkbook</p>
<p> Set feuille = wb. Feuilles(«&nbsp;Devis&nbsp;»)</p>
<p> dossierAdresse = Sheets(«&nbsp;Paramètres&nbsp;»). Gamme(«&nbsp;K9&nbsp;»). Valeur &amp; «&nbsp;\&nbsp;»</p>
<p> nomDocument = feuille. Gamme(«&nbsp;J10&nbsp;»). Valeur</p>
<p>&nbsp;&nbsp;&#8216;Mettre à plage l adresse de la plage à imprimer</p>
<p> plage = «&nbsp;$C$6:$M$53&nbsp;» </p>
<p>&nbsp;&nbsp;Application.ScreenUpdating = False</p>
<p> Avec feuille. PageSetup</p>
<p> . PrintArea = plage</p>
<p> . FitToPagesTall = 1</p>
<p> . FitToPagesWide = 1&#8242; Définissez FitToPagesWide sur 1</p>
<p> . LeftMargin = Application.InchesToPoints(0)</p>
<p> . RightMargin = Application.InchesToPoints(0)</p>
<p> . TopMargin = Application.InchesToPoints(0)</p>
<p> . BottomMargin = Application.InchesToPoints(0)</p>
<p> Terminez par</p>
<p> Avec feuille</p>
<p> iVis = . Visible</p>
<p> . Visible = xlSheetVisible</p>
<blockquote><p><strong><em> . Activer</em></strong></p></blockquote>
<p><strong><em> . Type ExportAsFixedFormat :=xlTypePDF, _</em></strong></p>
<p><strong><em> Nom de fichier:=dossierAdresse &amp; nomDocument &amp; «&nbsp;.pdf&nbsp;», _</em></strong></p>
<p><strong><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Quality:=xlQualityStandard, IncludeDocProperties:=True, _</em></strong></p>
<blockquote><p><strong><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IgnorePrintAreas:=False, OpenAfterPublish:=True</em></strong></p></p><p><p></p></blockquote>
<p> . Visible = iVis</p>
<p> Terminez par</p>
<p> Application.ScreenUpdating = Vrai</p>
<p>Fin de la sous-section</p>
<p>Je vous prie de m’aider a trouver une correction a la partie entre guillemets. Merci</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Bruce Conradie		</title>
		<link>https://powerspreadsheets.com/save-excel-file-pdf-vba/#comment-412</link>

		<dc:creator><![CDATA[Bruce Conradie]]></dc:creator>
		<pubDate>Thu, 13 Oct 2022 09:32:34 +0000</pubDate>
		<guid isPermaLink="false">https://powerspreadsheets.com/?p=5051#comment-412</guid>

					<description><![CDATA[Thank you. Solved a problem with printing just one worksheet. Much appreciated.]]></description>
			<content:encoded><![CDATA[<p>Thank you. Solved a problem with printing just one worksheet. Much appreciated.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: David		</title>
		<link>https://powerspreadsheets.com/save-excel-file-pdf-vba/#comment-392</link>

		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Wed, 10 Aug 2022 13:45:51 +0000</pubDate>
		<guid isPermaLink="false">https://powerspreadsheets.com/?p=5051#comment-392</guid>

					<description><![CDATA[For years I&#039;ve used an intermediary program, PDFCreator, to act as a printer that can be set to save the print output to a PDF. I had a complicated VBA routine that searched the registry for this printer&#039;s name, switch to the printer, saved the PDF, and then reverted to the original printer. It worked well for over a decade, and still works to this day.

This works so much easier!

This macro is saved in my Personal.xlsb file and is attached as a QuickAccess button.

&lt;pre class=&quot;ql-syntax&quot; spellcheck=&quot;false&quot;&gt;Sub macExportToPDF()

&#039;
&#039; Modernized version of &#039;macPrintToPDF&#039; macro, no longer uses PDFCreator
&#039;
&#039; More info at: https://powerspreadsheets.com/save-excel-file-pdf-vba/#Parameter-3-Quality
&#039;
&#039; macExportToPDF Macro
&#039; Use in-built ability to save Print Range to PDF
&#039; Uses workbook FileName to save on user&#039;s Desktop
&#039;

Dim sPath, FileNameToSave

&#160;&#160;&#160; &#039;Set path to user&#039;s DESKTOP
&#160;&#160;&#160; sPath = Environ(&quot;USERPROFILE&quot;) &#038; &quot;\Desktop\&quot;
&#160;&#160; &#160;
&#160;&#160;&#160; &#039;Get workbook filename, including extension
&#160;&#160;&#160; FileNameToSave = ActiveWorkbook.Name
&#160;&#160; &#160;
&#160;&#160;&#160; &#039;Strip extension
&#160;&#160;&#160; FileNameToSave = Left(FileNameToSave, InStrRev(FileNameToSave, &quot;.&quot;) - 1)
&#160;&#160; &#160;
&#160;&#160;&#160; &#039;Set final name to SaveAs
&#160;&#160;&#160; FileNameToSave = sPath &#038; FileNameToSave &#038; &quot;.pdf&quot;
&#160;&#160;&#160;&#160;&#160;&#160; &#160;
&#160;&#160;&#160; &#039;Publish to Desktop
&#160;&#160;&#160; ActiveSheet.ExportAsFixedFormat _
&#160;&#160;&#160;&#160;&#160;&#160;&#160; Type:=xlTypePDF, _
&#160;&#160;&#160;&#160;&#160;&#160;&#160; Filename:=FileNameToSave, _
&#160;&#160;&#160;&#160;&#160;&#160;&#160; Quality:=xlQualityStandard, _
&#160;&#160;&#160;&#160;&#160;&#160;&#160; OpenAfterPublish:=False, _
&#160;&#160;&#160;&#160;&#160;&#160;&#160; IgnorePrintAreas:=False
&#160;&#160;&#160;&#160;&#160;&#160; &#160;
End Sub


&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>For years I&#8217;ve used an intermediary program, PDFCreator, to act as a printer that can be set to save the print output to a PDF. I had a complicated VBA routine that searched the registry for this printer&#8217;s name, switch to the printer, saved the PDF, and then reverted to the original printer. It worked well for over a decade, and still works to this day.</p>
<p>This works so much easier!</p>
<p>This macro is saved in my Personal.xlsb file and is attached as a QuickAccess button.</p>
<pre class="ql-syntax" spellcheck="false">Sub macExportToPDF()

'
' Modernized version of 'macPrintToPDF' macro, no longer uses PDFCreator
'
' More info at: https://powerspreadsheets.com/save-excel-file-pdf-vba/#Parameter-3-Quality
'
' macExportToPDF Macro
' Use in-built ability to save Print Range to PDF
' Uses workbook FileName to save on user's Desktop
'

Dim sPath, FileNameToSave

&nbsp;&nbsp;&nbsp; 'Set path to user's DESKTOP
&nbsp;&nbsp;&nbsp; sPath = Environ("USERPROFILE") &amp; "\Desktop\"
&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp;&nbsp; 'Get workbook filename, including extension
&nbsp;&nbsp;&nbsp; FileNameToSave = ActiveWorkbook.Name
&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp;&nbsp; 'Strip extension
&nbsp;&nbsp;&nbsp; FileNameToSave = Left(FileNameToSave, InStrRev(FileNameToSave, ".") - 1)
&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp;&nbsp; 'Set final name to SaveAs
&nbsp;&nbsp;&nbsp; FileNameToSave = sPath &amp; FileNameToSave &amp; ".pdf"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp;&nbsp; 'Publish to Desktop
&nbsp;&nbsp;&nbsp; ActiveSheet.ExportAsFixedFormat _
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Type:=xlTypePDF, _
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Filename:=FileNameToSave, _
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Quality:=xlQualityStandard, _
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OpenAfterPublish:=False, _
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IgnorePrintAreas:=False
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
End Sub


</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Luckyearl Earl		</title>
		<link>https://powerspreadsheets.com/save-excel-file-pdf-vba/#comment-205</link>

		<dc:creator><![CDATA[Luckyearl Earl]]></dc:creator>
		<pubDate>Sat, 08 Jul 2017 22:05:00 +0000</pubDate>
		<guid isPermaLink="false">https://powerspreadsheets.com/?p=5051#comment-205</guid>

					<description><![CDATA[Hi Jorge
Brilliant writeup with great explanation. Manged to add Active x button to create PDF&#039;s.Manged to even print in landscape.Only hitch,my shortcoming, unable to save to folder on desktop.

I have kids with different logins, with different desktop, just wondering if you could help with path to save.

Filename:=ActiveWorkbook.Path &#038; &quot;&quot; &#038; ActiveSheet.Range(&quot;F5&quot;).Value, _
where I cud to save to a folder &quot;%systemdrive%%users%%currant User%DesktopMaths&quot;

Many Thanks

I am using

Sub Save_Excel_As_PDF_7()
With ActiveSheet.PageSetup
    .Orientation = xlPortrait
   End With

ActiveSheet.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:=ActiveWorkbook.Path &#038; &quot;&quot; &#038; ActiveSheet.Range(&quot;F5&quot;).Value, _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=False, _
    IgnorePrintAreas:=False, _
    From:=1, _
    to:=5, _
    OpenAfterPublish:=True
End Sub]]></description>
			<content:encoded><![CDATA[<p>Hi Jorge<br />
Brilliant writeup with great explanation. Manged to add Active x button to create PDF&#8217;s.Manged to even print in landscape.Only hitch,my shortcoming, unable to save to folder on desktop.</p>
<p>I have kids with different logins, with different desktop, just wondering if you could help with path to save.</p>
<p>Filename:=ActiveWorkbook.Path &amp; &#8220;&#8221; &amp; ActiveSheet.Range(&#8220;F5&#8221;).Value, _<br />
where I cud to save to a folder &#8220;%systemdrive%%users%%currant User%DesktopMaths&#8221;</p>
<p>Many Thanks</p>
<p>I am using</p>
<p>Sub Save_Excel_As_PDF_7()<br />
With ActiveSheet.PageSetup<br />
    .Orientation = xlPortrait<br />
   End With</p>
<p>ActiveSheet.ExportAsFixedFormat _<br />
    Type:=xlTypePDF, _<br />
    Filename:=ActiveWorkbook.Path &amp; &#8220;&#8221; &amp; ActiveSheet.Range(&#8220;F5&#8221;).Value, _<br />
    Quality:=xlQualityStandard, _<br />
    IncludeDocProperties:=False, _<br />
    IgnorePrintAreas:=False, _<br />
    From:=1, _<br />
    to:=5, _<br />
    OpenAfterPublish:=True<br />
End Sub</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Alice		</title>
		<link>https://powerspreadsheets.com/save-excel-file-pdf-vba/#comment-142</link>

		<dc:creator><![CDATA[Alice]]></dc:creator>
		<pubDate>Tue, 07 Mar 2017 17:13:00 +0000</pubDate>
		<guid isPermaLink="false">https://powerspreadsheets.com/?p=5051#comment-142</guid>

					<description><![CDATA[Hi Jorge, this has been incredibly helpful, I will keep coming back for other tutorials. 

Would you be willing to advise how to add one more element into your code: printing only visible sheets, please? (I am customising and building on top of example 8).
In my workbook in question, some sheets are previously turned .xlVeryHidden by a macro, as they are only assisting sheets and should not be seen by the end-user / workbook reader. 
Is there a way I can make sure these do not get printed into the PDF?
Thank you very much.
Alice]]></description>
			<content:encoded><![CDATA[<p>Hi Jorge, this has been incredibly helpful, I will keep coming back for other tutorials. </p>
<p>Would you be willing to advise how to add one more element into your code: printing only visible sheets, please? (I am customising and building on top of example 8).<br />
In my workbook in question, some sheets are previously turned .xlVeryHidden by a macro, as they are only assisting sheets and should not be seen by the end-user / workbook reader.<br />
Is there a way I can make sure these do not get printed into the PDF?<br />
Thank you very much.<br />
Alice</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Ivan D'souza		</title>
		<link>https://powerspreadsheets.com/save-excel-file-pdf-vba/#comment-132</link>

		<dc:creator><![CDATA[Ivan D'souza]]></dc:creator>
		<pubDate>Wed, 01 Feb 2017 10:57:00 +0000</pubDate>
		<guid isPermaLink="false">https://powerspreadsheets.com/?p=5051#comment-132</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://powerspreadsheets.com/save-excel-file-pdf-vba/#comment-118&quot;&gt;squishysdomain&lt;/a&gt;.

Hi Jorge,
Your article was amazing and very informative.
I would like to add an addendum to squishysdomain&#039;s question.
The difference is that I have certain pages using page breaks in the sheets. What I need is, i need to have only the 5th page from the first sheet, 4th page for the second sheet, 6th page from the third sheet and so on, for a couple of sheets and then combine them into one PDF file.

I have searched everywhere for a solution for this type of a situation but in vain!! 

I&#039;d appreciate any solution :)]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://powerspreadsheets.com/save-excel-file-pdf-vba/#comment-118">squishysdomain</a>.</p>
<p>Hi Jorge,<br />
Your article was amazing and very informative.<br />
I would like to add an addendum to squishysdomain&#8217;s question.<br />
The difference is that I have certain pages using page breaks in the sheets. What I need is, i need to have only the 5th page from the first sheet, 4th page for the second sheet, 6th page from the third sheet and so on, for a couple of sheets and then combine them into one PDF file.</p>
<p>I have searched everywhere for a solution for this type of a situation but in vain!! </p>
<p>I&#8217;d appreciate any solution 🙂</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: squishysdomain		</title>
		<link>https://powerspreadsheets.com/save-excel-file-pdf-vba/#comment-118</link>

		<dc:creator><![CDATA[squishysdomain]]></dc:creator>
		<pubDate>Thu, 12 Jan 2017 21:16:00 +0000</pubDate>
		<guid isPermaLink="false">https://powerspreadsheets.com/?p=5051#comment-118</guid>

					<description><![CDATA[Thanks for this - it was exactly what I needed.]]></description>
			<content:encoded><![CDATA[<p>Thanks for this &#8211; it was exactly what I needed.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Bernardo NG		</title>
		<link>https://powerspreadsheets.com/save-excel-file-pdf-vba/#comment-100</link>

		<dc:creator><![CDATA[Bernardo NG]]></dc:creator>
		<pubDate>Wed, 30 Nov 2016 22:21:00 +0000</pubDate>
		<guid isPermaLink="false">https://powerspreadsheets.com/?p=5051#comment-100</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://powerspreadsheets.com/save-excel-file-pdf-vba/#comment-89&quot;&gt;Bernardo NG&lt;/a&gt;.

Hi Jorge.

Sorry for my late reply. I was able to find and fix the problems with my macro, thanks to your help and your very helpful arcticle. Many thanks!

My macro, actually, needs to highlight the header cell and the cell in the column to the left of the first column, to indicate the position of the active cell. Also, before highlighting the next selected cell, it needs to clear the previously highlighted cells.
 https://uploads.disquscdn.com/images/7a88d2e1cdc2a7c6503e2eccd03f1bfd704c9a34b987669792fa385b32b43953.png  https://uploads.disquscdn.com/images/61b5690134f9f9e30f54dd2005fb7c88a253afcaa7f5351bd21c1ccefe610c40.png 
Sub Worksheet_SelectionChange(ByVal Target As Range)

    &#039;Macro to highlight row and column of active cell
    
    Application.ScreenUpdating = False
    
    iChange = False
    
    &#039;Loop through tables to clear highlighted cells
    For iCounter = 1 To ActiveSheet.ListObjects.Count
    
        With ActiveSheet.ListObjects(iCounter)
                
            &#039;get header row range
            iHeaderRange = .HeaderRowRange.Address

            &#039;get first body cell
            iBodyFirstCellColNum = .DataBodyRange(1, 1).Column &#039;as a number

            &#039;Clear interior color of previously highlighted cells
            Range(iHeaderRange).Interior.ColorIndex = xlColorIndexNone
            Columns(iBodyFirstCellColNum).Offset(0, -1).Interior.ColorIndex = xlColorIndexNone
    
        End With
        
    Next iCounter
    
    &#039;Loop through first and penultimate tables
    For iCounterMod = 1 To ActiveSheet.ListObjects.Count - 1
    
        With ActiveSheet.ListObjects(iCounterMod)

            &#039;get first header row
            iHeaderRow = .HeaderRowRange(1).Row
            
            &#039;get body range
            iBodyRange = .DataBodyRange.Address
            &#039;get first body cell
            iBodyFirstCellColNum = .DataBodyRange(1, 1).Column &#039;as a number
            
            &#039;Get column index of selected cell
            Col = ActiveCell.Column
            &#039;Get row index of selected cell
            Row = ActiveCell.Row

        End With
        
        &#039;if you select more than 1 cell, sub ends
        If Target.Cells.CountLarge &#062; 1 Then Exit Sub
        
        &#039;if you selected a body cell
        If Not Intersect(Target, Me.Range(iBodyRange)) Is Nothing Then
            
            &#039;iChange = True, i.e., some cells in first and penultimate tables were highlighted
            iChange = True
        
            &#039;Check if you are in an odd line
            If (Row Mod 2 = 0 And iHeaderRow Mod 2 = 0) Or (Row Mod 2  0 And iHeaderRow Mod 2  0) Then
    
                &#039;Highlight cells
                Cells(Row, iBodyFirstCellColNum).Offset(0, -1).Interior.ColorIndex = 37
                Cells(Row - 1, iBodyFirstCellColNum).Offset(0, -1).Interior.ColorIndex = 37
                Cells(iHeaderRow, Col).Interior.ColorIndex = 37
                
            Else
            
                &#039;Highlight cells
                Cells(Row, iBodyFirstCellColNum).Offset(0, -1).Interior.ColorIndex = 37
                Cells(Row + 1, iBodyFirstCellColNum).Offset(0, -1).Interior.ColorIndex = 37
                Cells(iHeaderRow, Col).Interior.ColorIndex = 37
                    
            End If
            
            &#039;if iChange = True (i.e., some cells in first and penultimate tables were highlighted), exit for loop
            If iChange Then Exit For
            
        End If

    Next iCounterMod
    
    &#039;if iChange = False (i.e., no cells in first and penultimate tables were highlighted), go to last table
    If Not iChange Then
    
        &#039;Loop through last table
        For iCounterVeh = ActiveSheet.ListObjects.Count To ActiveSheet.ListObjects.Count
        
            With ActiveSheet.ListObjects(iCounterVeh)

                &#039;get first header row
                iHeaderRow = .HeaderRowRange(1).Row
                
                &#039;get body range
                iBodyRange = .DataBodyRange.Address
                &#039;get first body cell
                iBodyFirstCellColNum = .DataBodyRange(1, 1).Column &#039;as a number
                
                &#039;Get column index of selected cell
                Col = ActiveCell.Column
                &#039;Get row index of selected cell
                Row = ActiveCell.Row
            
            End With
            
            If Target.Cells.Count &#062; 1 Then Exit Sub &#039;If you select more than 1 cell, sub ends
            
            If Not Intersect(Target, Me.Range(iBodyRange)) Is Nothing Then &#039;If you selected a body cell

                &#039;Highlight cells
                Cells(Row, iBodyFirstCellColNum).Offset(0, -1).Interior.ColorIndex = 37
                Cells(iHeaderRow, Col).Interior.ColorIndex = 37

            End If
                    
        Next iCounterVeh
    
    End If
    
    Application.ScreenUpdating = True

End Sub]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://powerspreadsheets.com/save-excel-file-pdf-vba/#comment-89">Bernardo NG</a>.</p>
<p>Hi Jorge.</p>
<p>Sorry for my late reply. I was able to find and fix the problems with my macro, thanks to your help and your very helpful arcticle. Many thanks!</p>
<p>My macro, actually, needs to highlight the header cell and the cell in the column to the left of the first column, to indicate the position of the active cell. Also, before highlighting the next selected cell, it needs to clear the previously highlighted cells.<br />
 <a href="https://uploads.disquscdn.com/images/7a88d2e1cdc2a7c6503e2eccd03f1bfd704c9a34b987669792fa385b32b43953.png" rel="nofollow ugc">https://uploads.disquscdn.com/images/7a88d2e1cdc2a7c6503e2eccd03f1bfd704c9a34b987669792fa385b32b43953.png</a>  <a href="https://uploads.disquscdn.com/images/61b5690134f9f9e30f54dd2005fb7c88a253afcaa7f5351bd21c1ccefe610c40.png" rel="nofollow ugc">https://uploads.disquscdn.com/images/61b5690134f9f9e30f54dd2005fb7c88a253afcaa7f5351bd21c1ccefe610c40.png</a><br />
Sub Worksheet_SelectionChange(ByVal Target As Range)</p>
<p>    &#8216;Macro to highlight row and column of active cell</p>
<p>    Application.ScreenUpdating = False</p>
<p>    iChange = False</p>
<p>    &#8216;Loop through tables to clear highlighted cells<br />
    For iCounter = 1 To ActiveSheet.ListObjects.Count</p>
<p>        With ActiveSheet.ListObjects(iCounter)</p>
<p>            &#8216;get header row range<br />
            iHeaderRange = .HeaderRowRange.Address</p>
<p>            &#8216;get first body cell<br />
            iBodyFirstCellColNum = .DataBodyRange(1, 1).Column &#8216;as a number</p>
<p>            &#8216;Clear interior color of previously highlighted cells<br />
            Range(iHeaderRange).Interior.ColorIndex = xlColorIndexNone<br />
            Columns(iBodyFirstCellColNum).Offset(0, -1).Interior.ColorIndex = xlColorIndexNone</p>
<p>        End With</p>
<p>    Next iCounter</p>
<p>    &#8216;Loop through first and penultimate tables<br />
    For iCounterMod = 1 To ActiveSheet.ListObjects.Count &#8211; 1</p>
<p>        With ActiveSheet.ListObjects(iCounterMod)</p>
<p>            &#8216;get first header row<br />
            iHeaderRow = .HeaderRowRange(1).Row</p>
<p>            &#8216;get body range<br />
            iBodyRange = .DataBodyRange.Address<br />
            &#8216;get first body cell<br />
            iBodyFirstCellColNum = .DataBodyRange(1, 1).Column &#8216;as a number</p>
<p>            &#8216;Get column index of selected cell<br />
            Col = ActiveCell.Column<br />
            &#8216;Get row index of selected cell<br />
            Row = ActiveCell.Row</p>
<p>        End With</p>
<p>        &#8216;if you select more than 1 cell, sub ends<br />
        If Target.Cells.CountLarge &gt; 1 Then Exit Sub</p>
<p>        &#8216;if you selected a body cell<br />
        If Not Intersect(Target, Me.Range(iBodyRange)) Is Nothing Then</p>
<p>            &#8216;iChange = True, i.e., some cells in first and penultimate tables were highlighted<br />
            iChange = True</p>
<p>            &#8216;Check if you are in an odd line<br />
            If (Row Mod 2 = 0 And iHeaderRow Mod 2 = 0) Or (Row Mod 2  0 And iHeaderRow Mod 2  0) Then</p>
<p>                &#8216;Highlight cells<br />
                Cells(Row, iBodyFirstCellColNum).Offset(0, -1).Interior.ColorIndex = 37<br />
                Cells(Row &#8211; 1, iBodyFirstCellColNum).Offset(0, -1).Interior.ColorIndex = 37<br />
                Cells(iHeaderRow, Col).Interior.ColorIndex = 37</p>
<p>            Else</p>
<p>                &#8216;Highlight cells<br />
                Cells(Row, iBodyFirstCellColNum).Offset(0, -1).Interior.ColorIndex = 37<br />
                Cells(Row + 1, iBodyFirstCellColNum).Offset(0, -1).Interior.ColorIndex = 37<br />
                Cells(iHeaderRow, Col).Interior.ColorIndex = 37</p>
<p>            End If</p>
<p>            &#8216;if iChange = True (i.e., some cells in first and penultimate tables were highlighted), exit for loop<br />
            If iChange Then Exit For</p>
<p>        End If</p>
<p>    Next iCounterMod</p>
<p>    &#8216;if iChange = False (i.e., no cells in first and penultimate tables were highlighted), go to last table<br />
    If Not iChange Then</p>
<p>        &#8216;Loop through last table<br />
        For iCounterVeh = ActiveSheet.ListObjects.Count To ActiveSheet.ListObjects.Count</p>
<p>            With ActiveSheet.ListObjects(iCounterVeh)</p>
<p>                &#8216;get first header row<br />
                iHeaderRow = .HeaderRowRange(1).Row</p>
<p>                &#8216;get body range<br />
                iBodyRange = .DataBodyRange.Address<br />
                &#8216;get first body cell<br />
                iBodyFirstCellColNum = .DataBodyRange(1, 1).Column &#8216;as a number</p>
<p>                &#8216;Get column index of selected cell<br />
                Col = ActiveCell.Column<br />
                &#8216;Get row index of selected cell<br />
                Row = ActiveCell.Row</p>
<p>            End With</p>
<p>            If Target.Cells.Count &gt; 1 Then Exit Sub &#8216;If you select more than 1 cell, sub ends</p>
<p>            If Not Intersect(Target, Me.Range(iBodyRange)) Is Nothing Then &#8216;If you selected a body cell</p>
<p>                &#8216;Highlight cells<br />
                Cells(Row, iBodyFirstCellColNum).Offset(0, -1).Interior.ColorIndex = 37<br />
                Cells(iHeaderRow, Col).Interior.ColorIndex = 37</p>
<p>            End If</p>
<p>        Next iCounterVeh</p>
<p>    End If</p>
<p>    Application.ScreenUpdating = True</p>
<p>End Sub</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Bernardo NG		</title>
		<link>https://powerspreadsheets.com/save-excel-file-pdf-vba/#comment-89</link>

		<dc:creator><![CDATA[Bernardo NG]]></dc:creator>
		<pubDate>Mon, 21 Nov 2016 14:17:00 +0000</pubDate>
		<guid isPermaLink="false">https://powerspreadsheets.com/?p=5051#comment-89</guid>

					<description><![CDATA[Hi, Jorge!

It worked perfectly! I&#039;ve just made some adjustments.

Many thanks!!!



 https://uploads.disquscdn.com/images/4d599e0175d8eb0cb244e0920a614de1a4ff933da1ffdc5198058c8302a18a82.png]]></description>
			<content:encoded><![CDATA[<p>Hi, Jorge!</p>
<p>It worked perfectly! I&#8217;ve just made some adjustments.</p>
<p>Many thanks!!!</p>
<p> <a href="https://uploads.disquscdn.com/images/4d599e0175d8eb0cb244e0920a614de1a4ff933da1ffdc5198058c8302a18a82.png" rel="nofollow ugc">https://uploads.disquscdn.com/images/4d599e0175d8eb0cb244e0920a614de1a4ff933da1ffdc5198058c8302a18a82.png</a></p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 

Served from: powerspreadsheets.com @ 2026-05-14 12:44:40 by W3 Total Cache
-->