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;
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
add a comment |
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
add a comment |
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
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
excel vba access-vba ms-access-2016
edited Mar 23 at 1:54
ashleedawg
13.1k42554
13.1k42554
asked Mar 22 at 23:59
ezybusyezybusy
195
195
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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
works as expected. Thank you very much.
– ezybusy
Mar 24 at 11:54
add a comment |
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)
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
works as expected. Thank you very much.
– ezybusy
Mar 24 at 11:54
add a comment |
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
works as expected. Thank you very much.
– ezybusy
Mar 24 at 11:54
add a comment |
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
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
answered Mar 23 at 1:52
DigiwiseDigiwise
915
915
works as expected. Thank you very much.
– ezybusy
Mar 24 at 11:54
add a comment |
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
add a comment |
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)
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
add a comment |
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)
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
add a comment |
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)
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)
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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