{"id":4224,"date":"2014-09-15T11:45:29","date_gmt":"2014-09-15T11:45:29","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/wp\/?p=4224"},"modified":"2022-08-12T11:43:09","modified_gmt":"2022-08-12T11:43:09","slug":"page-setup-orientation","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/","title":{"rendered":"Excel VBA Tips – Two excel VBA Tricks to help in day-to-day Coding"},"content":{"rendered":"

Dear Readers,
\n 
\nIn this article I am going to share with you – Two little VBA code which will help you in your day-to-day coding life.<\/p>\n

1. How to disable Copying Objects with cells through VBA<\/h1>\n

When you are trying to move or copy a Sheet or set of Sheets in to another workbook then by default it copies everything. Even the objects lying in that cell, range or Sheet also gets copied in to new Sheet. You may not like to copy all the objects along with the cell contents all the time. <\/p>\n

For example:<\/h3>\n

If you have a Summary page in Excel and you have put a “Download” button in that page which makes a copy of your Summary sheet in a new workbook. In this case in the downloaded Summary sheet you would definitely not like to keep the Download button.. right?? Because there is no point of keeping it there. Then here is the solution – before executing the copy statement you need to disable CopyObjectsWithCells<\/strong> method:<\/p>\n

\r\n'Disable copying of objects with cells before executing the copy statement\r\nApplication.CopyObjectsWithCells = False\r\n'Now Copy the Sheet in to a new Workbook\r\nSheets(\"Summary\").Copy\r\n'Now again enable the CopyObjectWithCells back\r\nApplication.CopyObjectsWithCells = True\r\n<\/code><\/pre>\n

2. VBA to Change the Orientation of the Sheet before printing<\/h1>\n

Sometimes you may need to change the orientation of the page before printing from Excel VBA. It could be used even while exporting your Sheet to PDF format. All you need to do is before executing the Print statement or Export statement you need to Set the Page orientation using below statement:<\/p>\n

\r\n'To set the orientation as LandScape\r\nSheet1.PageSetup.Orientation = xlLandscape\r\n'To set the orientation as Portrait\r\nSheet1.PageSetup.Orientation = xlPortrait\r\n<\/code><\/pre>\n

Example: Convert your Sheet in to pdf with LandScape Orientation<\/h2>\n
\r\nSub Convert_To_PDF_LandScape()\r\n    With ActiveSheet\r\n    'First Set the orientation of the page\r\n        .PageSetup.Orientation = xlLandscape\r\n    'Now Export the Sheet to PDF\r\n        .ExportAsFixedFormat _\r\n        Type:=xlTypePDF, _\r\n        Filename:=\"C:\\Users\\Vish\\File_Name.pdf\", _\r\n        Quality:=xlQualityStandard, _\r\n        IncludeDocProperties:=True, _\r\n        IgnorePrintAreas:=False, _\r\n        OpenAfterPublish:=False\r\n    End With\r\nEnd Sub\r\n<\/code><\/pre>\n

Example: Convert your Sheet in to pdf with Portrait Orientation<\/h2>\n
\r\nSub Convert_To_PDF_LandScape()\r\n    With ActiveSheet\r\n    'First Set the orientation of the page\r\n        .PageSetup.Orientation = xlPortrait\r\n    'Now Export the Sheet to PDF\r\n        .ExportAsFixedFormat _\r\n        Type:=xlTypePDF, _\r\n        Filename:=\"C:\\Users\\Vish\\File_Name.pdf\", _\r\n        Quality:=xlQualityStandard, _\r\n        IncludeDocProperties:=True, _\r\n        IgnorePrintAreas:=False, _\r\n        OpenAfterPublish:=False\r\n    End With\r\nEnd Sub\r\n<\/code><\/pre>\n

To read more about converting excel sheet in to pdf click here<\/a><\/h2>\n<\/span>","protected":false},"excerpt":{"rendered":"

Dear Readers,   In this article I am going to share with you – Two little VBA code which will help you in your day-to-day coding life. 1. How to disable Copying Objects with cells through VBA When you are trying to move or copy a Sheet or set of Sheets in to another workbook […]<\/p>\n","protected":false},"author":45,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1679,1676],"tags":[],"class_list":["post-4224","post","type-post","status-publish","format-standard","hentry","category-excel-macro-beginner","category-excel-tips"],"yoast_head":"\nUseful Excel VBA tips - Helpful in your day to day Coding at Work<\/title>\n<meta name=\"description\" content=\"VBA Tips to disable Copying Objects with cells through VBA.. Change Page setup orientation through excel vba. Change Orientation to Landscape or Portrait.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Excel VBA Tips - Two excel VBA Tricks to help in day-to-day Coding\" \/>\n<meta property=\"og:description\" content=\"VBA Tips to disable Copying Objects with cells through VBA.. Change Page setup orientation through excel vba. Change Orientation to Landscape or Portrait.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/\" \/>\n<meta property=\"og:site_name\" content=\"Let's excel in Excel\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/www.facebook.com\/vmlogger\" \/>\n<meta property=\"article:author\" content=\"http:\/\/www.facebook.com\/vmlogger\" \/>\n<meta property=\"article:published_time\" content=\"2014-09-15T11:45:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-12T11:43:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/vmlogger.com_-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Vishwamitra Mishra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/www.twitter.com\/learnexcelmacro\" \/>\n<meta name=\"twitter:site\" content=\"@learnexcelmacro\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vishwamitra Mishra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/\"},\"author\":{\"name\":\"Vishwamitra Mishra\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"headline\":\"Excel VBA Tips – Two excel VBA Tricks to help in day-to-day Coding\",\"datePublished\":\"2014-09-15T11:45:29+00:00\",\"dateModified\":\"2022-08-12T11:43:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/\"},\"wordCount\":278,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"articleSection\":[\"Excel Macro Beginner\",\"Excel Tips\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/\",\"name\":\"Useful Excel VBA tips - Helpful in your day to day Coding at Work\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\"},\"datePublished\":\"2014-09-15T11:45:29+00:00\",\"dateModified\":\"2022-08-12T11:43:09+00:00\",\"description\":\"VBA Tips to disable Copying Objects with cells through VBA.. Change Page setup orientation through excel vba. Change Orientation to Landscape or Portrait.\",\"breadcrumb\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/vmlogger.com\/excel\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Excel Macro Beginner\",\"item\":\"https:\/\/vmlogger.com\/excel\/excel-macro-beginner\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Excel VBA Tips – Two excel VBA Tricks to help in day-to-day Coding\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\",\"url\":\"https:\/\/vmlogger.com\/excel\/\",\"name\":\"Let's excel in Excel\",\"description\":\"Let's share knowledge\",\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/vmlogger.com\/excel\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\",\"name\":\"Vishwamitra Mishra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png\",\"contentUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png\",\"width\":528,\"height\":560,\"caption\":\"Vishwamitra Mishra\"},\"logo\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/\"},\"description\":\"My name is Vishwamitra Mishra. Friends Call me Vishwa. I hold a Bachelor\u2019s Degree in Computer Science from D.A.V.V. Indore & currently working as a Technical Lead having over 7 years of experience.\",\"sameAs\":[\"http:\/\/www.learnexcelmacro.com\",\"http:\/\/www.facebook.com\/vmlogger\",\"https:\/\/x.com\/https:\/\/www.twitter.com\/learnexcelmacro\",\"https:\/\/www.youtube.com\/c\/VMLogger\"],\"url\":\"https:\/\/vmlogger.com\/excel\/author\/vishwamitra\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Useful Excel VBA tips - Helpful in your day to day Coding at Work","description":"VBA Tips to disable Copying Objects with cells through VBA.. Change Page setup orientation through excel vba. Change Orientation to Landscape or Portrait.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/","og_locale":"en_US","og_type":"article","og_title":"Excel VBA Tips - Two excel VBA Tricks to help in day-to-day Coding","og_description":"VBA Tips to disable Copying Objects with cells through VBA.. Change Page setup orientation through excel vba. Change Orientation to Landscape or Portrait.","og_url":"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/","og_site_name":"Let's excel in Excel","article_publisher":"http:\/\/www.facebook.com\/vmlogger","article_author":"http:\/\/www.facebook.com\/vmlogger","article_published_time":"2014-09-15T11:45:29+00:00","article_modified_time":"2022-08-12T11:43:09+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/vmlogger.com_-1.png","type":"image\/png"}],"author":"Vishwamitra Mishra","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/www.twitter.com\/learnexcelmacro","twitter_site":"@learnexcelmacro","twitter_misc":{"Written by":"Vishwamitra Mishra","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/#article","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/"},"author":{"name":"Vishwamitra Mishra","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"headline":"Excel VBA Tips – Two excel VBA Tricks to help in day-to-day Coding","datePublished":"2014-09-15T11:45:29+00:00","dateModified":"2022-08-12T11:43:09+00:00","mainEntityOfPage":{"@id":"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/"},"wordCount":278,"commentCount":2,"publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"articleSection":["Excel Macro Beginner","Excel Tips"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/","url":"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/","name":"Useful Excel VBA tips - Helpful in your day to day Coding at Work","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/#website"},"datePublished":"2014-09-15T11:45:29+00:00","dateModified":"2022-08-12T11:43:09+00:00","description":"VBA Tips to disable Copying Objects with cells through VBA.. Change Page setup orientation through excel vba. Change Orientation to Landscape or Portrait.","breadcrumb":{"@id":"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/vmlogger.com\/excel\/2014\/09\/page-setup-orientation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vmlogger.com\/excel\/"},{"@type":"ListItem","position":2,"name":"Excel Macro Beginner","item":"https:\/\/vmlogger.com\/excel\/excel-macro-beginner\/"},{"@type":"ListItem","position":3,"name":"Excel VBA Tips – Two excel VBA Tricks to help in day-to-day Coding"}]},{"@type":"WebSite","@id":"https:\/\/vmlogger.com\/excel\/#website","url":"https:\/\/vmlogger.com\/excel\/","name":"Let's excel in Excel","description":"Let's share knowledge","publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vmlogger.com\/excel\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5","name":"Vishwamitra Mishra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/","url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png","contentUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png","width":528,"height":560,"caption":"Vishwamitra Mishra"},"logo":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/"},"description":"My name is Vishwamitra Mishra. Friends Call me Vishwa. I hold a Bachelor\u2019s Degree in Computer Science from D.A.V.V. Indore & currently working as a Technical Lead having over 7 years of experience.","sameAs":["http:\/\/www.learnexcelmacro.com","http:\/\/www.facebook.com\/vmlogger","https:\/\/x.com\/https:\/\/www.twitter.com\/learnexcelmacro","https:\/\/www.youtube.com\/c\/VMLogger"],"url":"https:\/\/vmlogger.com\/excel\/author\/vishwamitra\/"}]}},"_links":{"self":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/4224"}],"collection":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/users\/45"}],"replies":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/comments?post=4224"}],"version-history":[{"count":0,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/4224\/revisions"}],"wp:attachment":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/media?parent=4224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/categories?post=4224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/tags?post=4224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}