Excel 2013 won't format as a table after importing from a CSV using VB script

BellaxPalus

New Member
Joined
Apr 26, 2013
Messages
6
I have a sheet that I am importing data from a CSV file that I then unlink it from the data and format it as a table. This works perfectly when I do it manually but when I attempt to do this with a Macro I always get a "Run-time Error 1001" unless I save and reopen the file.



I delete the external data connections using this bit of code from elsewhere in this forum

Code:
[/FONT][/COLOR][COLOR=#333333][FONT=Verdana]sub delete_Connections()[/FONT][/COLOR]

[COLOR=#333333][FONT=Verdana]do while activeworkbook.connections.count > 0[/FONT][/COLOR]

[COLOR=#333333][FONT=Verdana]activeworkbook.connections.item(activeworkbook.connections.count).delete[/FONT][/COLOR]

[COLOR=#333333][FONT=Verdana]loop[/FONT][/COLOR]

[COLOR=#333333][FONT=Verdana]end sub[/FONT][/COLOR][COLOR=#222222][FONT=Verdana]
https://www.mrexcel.com/forum/excel-questions/381140-macro-delete-all-exernal-data-connections-post3343454.html#post3343454



I also recorded my format steps so if there is a better way to format as a table I am open to improving the code.

Code:
Range("A1:F17").Select    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$F$17"), , xlYes).Name = _[/FONT][/COLOR]

[COLOR=#222222][FONT=Verdana]        "Table1"[/FONT][/COLOR]

[COLOR=#222222][FONT=Verdana]    Range("Table1[#All]").Select[/FONT][/COLOR]

[COLOR=#222222][FONT=Verdana]    ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleMedium2"


This code does remove the connections if you go into the connections manager, but something seems to hold it in memory until you close and reopen the file.



Having to close and open the file after the <g class="gr_ gr_28 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="28" style='background-position: -1px calc(100% + 3px); color: rgb(34, 34, 34); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px; font-style: normal; font-weight: 400; word-spacing: 0px; border-bottom-color: transparent; border-bottom-width: 2px; border-bottom-style: solid; display: inline; white-space: normal; orphans: 2; widows: 2; background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHdpZHRoPScxMDAlJyBoZWlnaHQ9JzEwMCUnPgogIDxsaW5lIG9wYWNpdHk9JzAuNzUnIHgxPSc0JyB5MT0nMTAwJScgeDI9JzEwMCUnIHkyPScxMDAlJyB0cmFuc2Zvcm09J3RyYW5zbGF0ZSgtMS41LCAtMi41KScgc3Ryb2tlLXdpZHRoPSczJyBzdHJva2UtbGluZWNhcD0ncm91bmQnIHN0cm9rZT0nI2ZjNTQ1NCcvPgo8L3N2Zz4K"); background-repeat: no-repeat; background-size: calc(100% + 1px) 100%; font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' data-gr-id="28">import</g> kind of removes the automation I am going for. I have a workaround where I have to launch a second script after importing to finish the formatting but I am trying to make this a one-button job so I can give it to others in my shop that have to do the same work.
 

Forum statistics

Threads
1,082,360
Messages
5,364,920
Members
400,815
Latest member
Joaquin Phoenix

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top