How to delete a column of an excel document created by exporting an access subform?How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?How to avoid using Select in Excel VBAIn Excel VBA 2010: How to destroy excel vba.application objectaccess 2010 getting max row in excel 2010excel replace function in access vbaHow do I highlight all text and wrap in data exported from Access to Excel using VBA?Extract IP Addresses in Microsoft Outlook using macrosSave .xlsx to .csv or .txt from Access VBAHow to import the entire row(s) containing current (today's) date from a excel file into another excel file automatically without opening with VBAhow to convert a column of text with html tags to formatted text in vba in excel

Copy previous line to current line from text file

How to increase the size of the cursor in Lubuntu 19.04?

Does it make sense for a function to return a rvalue reference

Does a picture or painting work with Wild Shape?

Word for Food that's Gone 'Bad', but is Still Edible?

Where is the documentation for this ex command?

60s/70s science fiction novel where a man (after years of trying) finally succeeds to make a coin levitate by sheer concentration

List of newcommands used

In Russian, how do you idiomatically express the idea of the figurative "overnight"?

How do LIGO and VIRGO know that a gravitational wave has its origin in a neutron star or a black hole?

Should I mention being denied entry to UK due to a confusion in my Visa and Ticket bookings?

How can internet speed be 10 times slower without a router than when using a router?

PWM 1Hz on solid state relay

Floor of Riemann zeta function

How to safely wipe a USB flash drive

Why did the Apollo 13 crew extend the LM landing gear?

Should I dumb down my writing in a foreign country?

What are the differences between credential stuffing and password spraying?

What is a smasher?

Out of scope work duties and resignation

I need a disease

Can I use a fetch land to shuffle my deck while the opponent has Ashiok, Dream Render in play?

How to use dependency injection and avoid temporal coupling?

How can I roleplay a follower-type character when I as a player have a leader-type personality?



How to delete a column of an excel document created by exporting an access subform?


How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?How to avoid using Select in Excel VBAIn Excel VBA 2010: How to destroy excel vba.application objectaccess 2010 getting max row in excel 2010excel replace function in access vbaHow do I highlight all text and wrap in data exported from Access to Excel using VBA?Extract IP Addresses in Microsoft Outlook using macrosSave .xlsx to .csv or .txt from Access VBAHow to import the entire row(s) containing current (today's) date from a excel file into another excel file automatically without opening with VBAhow to convert a column of text with html tags to formatted text in vba in excel






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I am trying to delete a column from a excel file created by exporting an access subform.



I use the following vba code to perform the export. The exported file contains are five column.



Private Sub CmdExporter_Click()
DoCmd.RunCommand acCmdSelectAllRecords
DoCmd.RunCommand acCmdCopy
Dim xlapp As Object
Set xlapp = CreateObject("Excel.Application")
With xlapp
.Workbooks.Add
.ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
False
.Cells.Select
.Cells.EntireColumn.AutoFit
.Visible = True
.Range("o1").Select
End With
End Sub


Can someone help me adjust the code in order to be able to delete the last column(5th column) as the excel document gets exported?










share|improve this question






























    1















    I am trying to delete a column from a excel file created by exporting an access subform.



    I use the following vba code to perform the export. The exported file contains are five column.



    Private Sub CmdExporter_Click()
    DoCmd.RunCommand acCmdSelectAllRecords
    DoCmd.RunCommand acCmdCopy
    Dim xlapp As Object
    Set xlapp = CreateObject("Excel.Application")
    With xlapp
    .Workbooks.Add
    .ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
    False
    .Cells.Select
    .Cells.EntireColumn.AutoFit
    .Visible = True
    .Range("o1").Select
    End With
    End Sub


    Can someone help me adjust the code in order to be able to delete the last column(5th column) as the excel document gets exported?










    share|improve this question


























      1












      1








      1








      I am trying to delete a column from a excel file created by exporting an access subform.



      I use the following vba code to perform the export. The exported file contains are five column.



      Private Sub CmdExporter_Click()
      DoCmd.RunCommand acCmdSelectAllRecords
      DoCmd.RunCommand acCmdCopy
      Dim xlapp As Object
      Set xlapp = CreateObject("Excel.Application")
      With xlapp
      .Workbooks.Add
      .ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
      False
      .Cells.Select
      .Cells.EntireColumn.AutoFit
      .Visible = True
      .Range("o1").Select
      End With
      End Sub


      Can someone help me adjust the code in order to be able to delete the last column(5th column) as the excel document gets exported?










      share|improve this question
















      I am trying to delete a column from a excel file created by exporting an access subform.



      I use the following vba code to perform the export. The exported file contains are five column.



      Private Sub CmdExporter_Click()
      DoCmd.RunCommand acCmdSelectAllRecords
      DoCmd.RunCommand acCmdCopy
      Dim xlapp As Object
      Set xlapp = CreateObject("Excel.Application")
      With xlapp
      .Workbooks.Add
      .ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
      False
      .Cells.Select
      .Cells.EntireColumn.AutoFit
      .Visible = True
      .Range("o1").Select
      End With
      End Sub


      Can someone help me adjust the code in order to be able to delete the last column(5th column) as the excel document gets exported?







      excel vba access-vba ms-access-2016






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 1:54









      ashleedawg

      13.1k42554




      13.1k42554










      asked Mar 22 at 23:59









      ezybusyezybusy

      195




      195






















          2 Answers
          2






          active

          oldest

          votes


















          1














          You can use Range.Delete to delete cells. A refined version of your sub is:



          Private Sub CmdExporter_Click()
          ' Create Excel app
          Dim xlapp As Object
          Set xlapp = CreateObject("Excel.Application")
          With xlapp
          .Visible = True ' show Excel app

          ' Create new workbook in Excel
          Dim xlWorkbook As Object
          Set xlWorkbook = .Workbooks.Add
          End With

          ' Get a reference to the workbook's first sheet
          Dim xlSheet As Object
          Set xlSheet = xlWorkbook.worksheets(1)

          ' Copy access data - done just before paste to reduce chance of clipboard being changed before paste
          DoCmd.RunCommand acCmdSelectAllRecords
          DoCmd.RunCommand acCmdCopy

          xlSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:=False ' Paste the data
          xlSheet.UsedRange.EntireColumn.AutoFit ' Auto fit column width

          ' Option 1: Delete last column
          xlSheet.UsedRange.Columns(xlSheet.UsedRange.Columns.Count).EntireColumn.Delete

          ' OR Option 2: Delete 5th column
          xlSheet.UsedRange.Columns(5).EntireColumn.Delete
          End Sub





          share|improve this answer























          • works as expected. Thank you very much.

            – ezybusy
            Mar 24 at 11:54


















          0














          There are many examples online showing how to delete an Excel column using Access VBA. Which one is best for you depends on what you have and what you're trying to do.



          Without having more specific information about your data or desired 'end-goal', I'd suggest that you may find it easier to use one of the methods specifically intended for exporting data from Access to Excel.



          For example, a single line of code:



          DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "Table1", "x:myOutputFile.xlsx", True, "myWorksheet"



          ...creates (or updates, if it exists and is closed) an Excel file x:myOutputFile.xlsx, creating (or updating if it exists) a sheet called myWorksheet, with the contents of table Table1. (For a partial dataset, you could specify a query name instead of table name.)




          More Information:



          • Microsoft Docs : DoCmd.TransferSpreadsheet method (Access)





          share|improve this answer























          • Further recommended reading: "How to create a Minimal, Complete, and Verifiable example" as well as "How to Ask" and "Writing the Perfect uestion".

            – ashleedawg
            Mar 23 at 1:51











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55309250%2fhow-to-delete-a-column-of-an-excel-document-created-by-exporting-an-access-subfo%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You can use Range.Delete to delete cells. A refined version of your sub is:



          Private Sub CmdExporter_Click()
          ' Create Excel app
          Dim xlapp As Object
          Set xlapp = CreateObject("Excel.Application")
          With xlapp
          .Visible = True ' show Excel app

          ' Create new workbook in Excel
          Dim xlWorkbook As Object
          Set xlWorkbook = .Workbooks.Add
          End With

          ' Get a reference to the workbook's first sheet
          Dim xlSheet As Object
          Set xlSheet = xlWorkbook.worksheets(1)

          ' Copy access data - done just before paste to reduce chance of clipboard being changed before paste
          DoCmd.RunCommand acCmdSelectAllRecords
          DoCmd.RunCommand acCmdCopy

          xlSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:=False ' Paste the data
          xlSheet.UsedRange.EntireColumn.AutoFit ' Auto fit column width

          ' Option 1: Delete last column
          xlSheet.UsedRange.Columns(xlSheet.UsedRange.Columns.Count).EntireColumn.Delete

          ' OR Option 2: Delete 5th column
          xlSheet.UsedRange.Columns(5).EntireColumn.Delete
          End Sub





          share|improve this answer























          • works as expected. Thank you very much.

            – ezybusy
            Mar 24 at 11:54















          1














          You can use Range.Delete to delete cells. A refined version of your sub is:



          Private Sub CmdExporter_Click()
          ' Create Excel app
          Dim xlapp As Object
          Set xlapp = CreateObject("Excel.Application")
          With xlapp
          .Visible = True ' show Excel app

          ' Create new workbook in Excel
          Dim xlWorkbook As Object
          Set xlWorkbook = .Workbooks.Add
          End With

          ' Get a reference to the workbook's first sheet
          Dim xlSheet As Object
          Set xlSheet = xlWorkbook.worksheets(1)

          ' Copy access data - done just before paste to reduce chance of clipboard being changed before paste
          DoCmd.RunCommand acCmdSelectAllRecords
          DoCmd.RunCommand acCmdCopy

          xlSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:=False ' Paste the data
          xlSheet.UsedRange.EntireColumn.AutoFit ' Auto fit column width

          ' Option 1: Delete last column
          xlSheet.UsedRange.Columns(xlSheet.UsedRange.Columns.Count).EntireColumn.Delete

          ' OR Option 2: Delete 5th column
          xlSheet.UsedRange.Columns(5).EntireColumn.Delete
          End Sub





          share|improve this answer























          • works as expected. Thank you very much.

            – ezybusy
            Mar 24 at 11:54













          1












          1








          1







          You can use Range.Delete to delete cells. A refined version of your sub is:



          Private Sub CmdExporter_Click()
          ' Create Excel app
          Dim xlapp As Object
          Set xlapp = CreateObject("Excel.Application")
          With xlapp
          .Visible = True ' show Excel app

          ' Create new workbook in Excel
          Dim xlWorkbook As Object
          Set xlWorkbook = .Workbooks.Add
          End With

          ' Get a reference to the workbook's first sheet
          Dim xlSheet As Object
          Set xlSheet = xlWorkbook.worksheets(1)

          ' Copy access data - done just before paste to reduce chance of clipboard being changed before paste
          DoCmd.RunCommand acCmdSelectAllRecords
          DoCmd.RunCommand acCmdCopy

          xlSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:=False ' Paste the data
          xlSheet.UsedRange.EntireColumn.AutoFit ' Auto fit column width

          ' Option 1: Delete last column
          xlSheet.UsedRange.Columns(xlSheet.UsedRange.Columns.Count).EntireColumn.Delete

          ' OR Option 2: Delete 5th column
          xlSheet.UsedRange.Columns(5).EntireColumn.Delete
          End Sub





          share|improve this answer













          You can use Range.Delete to delete cells. A refined version of your sub is:



          Private Sub CmdExporter_Click()
          ' Create Excel app
          Dim xlapp As Object
          Set xlapp = CreateObject("Excel.Application")
          With xlapp
          .Visible = True ' show Excel app

          ' Create new workbook in Excel
          Dim xlWorkbook As Object
          Set xlWorkbook = .Workbooks.Add
          End With

          ' Get a reference to the workbook's first sheet
          Dim xlSheet As Object
          Set xlSheet = xlWorkbook.worksheets(1)

          ' Copy access data - done just before paste to reduce chance of clipboard being changed before paste
          DoCmd.RunCommand acCmdSelectAllRecords
          DoCmd.RunCommand acCmdCopy

          xlSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:=False ' Paste the data
          xlSheet.UsedRange.EntireColumn.AutoFit ' Auto fit column width

          ' Option 1: Delete last column
          xlSheet.UsedRange.Columns(xlSheet.UsedRange.Columns.Count).EntireColumn.Delete

          ' OR Option 2: Delete 5th column
          xlSheet.UsedRange.Columns(5).EntireColumn.Delete
          End Sub






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 23 at 1:52









          DigiwiseDigiwise

          915




          915












          • works as expected. Thank you very much.

            – ezybusy
            Mar 24 at 11:54

















          • works as expected. Thank you very much.

            – ezybusy
            Mar 24 at 11:54
















          works as expected. Thank you very much.

          – ezybusy
          Mar 24 at 11:54





          works as expected. Thank you very much.

          – ezybusy
          Mar 24 at 11:54













          0














          There are many examples online showing how to delete an Excel column using Access VBA. Which one is best for you depends on what you have and what you're trying to do.



          Without having more specific information about your data or desired 'end-goal', I'd suggest that you may find it easier to use one of the methods specifically intended for exporting data from Access to Excel.



          For example, a single line of code:



          DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "Table1", "x:myOutputFile.xlsx", True, "myWorksheet"



          ...creates (or updates, if it exists and is closed) an Excel file x:myOutputFile.xlsx, creating (or updating if it exists) a sheet called myWorksheet, with the contents of table Table1. (For a partial dataset, you could specify a query name instead of table name.)




          More Information:



          • Microsoft Docs : DoCmd.TransferSpreadsheet method (Access)





          share|improve this answer























          • Further recommended reading: "How to create a Minimal, Complete, and Verifiable example" as well as "How to Ask" and "Writing the Perfect uestion".

            – ashleedawg
            Mar 23 at 1:51















          0














          There are many examples online showing how to delete an Excel column using Access VBA. Which one is best for you depends on what you have and what you're trying to do.



          Without having more specific information about your data or desired 'end-goal', I'd suggest that you may find it easier to use one of the methods specifically intended for exporting data from Access to Excel.



          For example, a single line of code:



          DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "Table1", "x:myOutputFile.xlsx", True, "myWorksheet"



          ...creates (or updates, if it exists and is closed) an Excel file x:myOutputFile.xlsx, creating (or updating if it exists) a sheet called myWorksheet, with the contents of table Table1. (For a partial dataset, you could specify a query name instead of table name.)




          More Information:



          • Microsoft Docs : DoCmd.TransferSpreadsheet method (Access)





          share|improve this answer























          • Further recommended reading: "How to create a Minimal, Complete, and Verifiable example" as well as "How to Ask" and "Writing the Perfect uestion".

            – ashleedawg
            Mar 23 at 1:51













          0












          0








          0







          There are many examples online showing how to delete an Excel column using Access VBA. Which one is best for you depends on what you have and what you're trying to do.



          Without having more specific information about your data or desired 'end-goal', I'd suggest that you may find it easier to use one of the methods specifically intended for exporting data from Access to Excel.



          For example, a single line of code:



          DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "Table1", "x:myOutputFile.xlsx", True, "myWorksheet"



          ...creates (or updates, if it exists and is closed) an Excel file x:myOutputFile.xlsx, creating (or updating if it exists) a sheet called myWorksheet, with the contents of table Table1. (For a partial dataset, you could specify a query name instead of table name.)




          More Information:



          • Microsoft Docs : DoCmd.TransferSpreadsheet method (Access)





          share|improve this answer













          There are many examples online showing how to delete an Excel column using Access VBA. Which one is best for you depends on what you have and what you're trying to do.



          Without having more specific information about your data or desired 'end-goal', I'd suggest that you may find it easier to use one of the methods specifically intended for exporting data from Access to Excel.



          For example, a single line of code:



          DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "Table1", "x:myOutputFile.xlsx", True, "myWorksheet"



          ...creates (or updates, if it exists and is closed) an Excel file x:myOutputFile.xlsx, creating (or updating if it exists) a sheet called myWorksheet, with the contents of table Table1. (For a partial dataset, you could specify a query name instead of table name.)




          More Information:



          • Microsoft Docs : DoCmd.TransferSpreadsheet method (Access)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 23 at 1:51









          ashleedawgashleedawg

          13.1k42554




          13.1k42554












          • Further recommended reading: "How to create a Minimal, Complete, and Verifiable example" as well as "How to Ask" and "Writing the Perfect uestion".

            – ashleedawg
            Mar 23 at 1:51

















          • Further recommended reading: "How to create a Minimal, Complete, and Verifiable example" as well as "How to Ask" and "Writing the Perfect uestion".

            – ashleedawg
            Mar 23 at 1:51
















          Further recommended reading: "How to create a Minimal, Complete, and Verifiable example" as well as "How to Ask" and "Writing the Perfect uestion".

          – ashleedawg
          Mar 23 at 1:51





          Further recommended reading: "How to create a Minimal, Complete, and Verifiable example" as well as "How to Ask" and "Writing the Perfect uestion".

          – ashleedawg
          Mar 23 at 1:51

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55309250%2fhow-to-delete-a-column-of-an-excel-document-created-by-exporting-an-access-subfo%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현