How do I highlight all text and wrap in data exported from Access to Excel using VBA? - ms-access

I am using VBA in Access to export a file into Excel and format the text in Excel. I am trying to highlight all data in Excel (once it has been exported) and then wrap that data using VBA code in Access.
How would I get this task completed?
Trying to use the code below is not working. The data starts in cell A1 and should end with the end xlright ans down (meaning, I do not have a set column or row where the data ends).
objApp.ActiveWorkbook.Worksheets(1).Activate
objApp.ActiveWorkbook.Worksheets(1).Range("A1").Select
objApp.ActiveWorkbook.Worksheets(1).Selection.End(xlToRight).Select
objApp.ActiveWorkbook.Worksheets(1).Selection.End(xlDown).Select
objApp.Selection.WrapText = True

Probably the following would work clearly for you:
objApp.ActiveWorkbook.Worksheets(1).usedrange.wraptext=true

Related

Paste CSV or Tab-Delimited data to excel with NO formatting

I'm pasting Tab Delimited data from Notepad++ to excel (about 50k rows and 3 columns). No matter how many different ways I try it, Excel wants to convert a cell containing one " to the next instance of " into one cell content.
For Example, if my data looked like this:
"Apple 1.0 Store
Banana 1.3 Store
"Cherry" 2.5 Garden
Watermelon 4.0 Field
The excel file looks like this:
Apple1.0StoreBanana1.3Store
Cherry 2.5GardenWatermelon4.0Field
One way to get around this is to open the file as a CSV in excel, however this leads to Excel formatting the number values to simplified ones using Excel's "General" format. So the data would look like the following:
"Apple 1 Store
Banana 1.3 Store
"Cherry" 2.5 Garden
Watermelon 4 Field
The data I'm getting is coming from SQL Server Studio so my options for file formats are:
.CSV
.Txt (Tab-delimited)
Copy Pasting from Query results
The solution I'm looking for is to have the data represented in Excel with no excel processing taking place on the quotations, numbers or any other cell contents.
Don't open the file directly in excel. Instead import it and control the data types and file layout.
Open a new excel document:
Select Data menu:
Select From Text in get External Data section.
Select file to import
On step 1 of import wizard select delimited
Click next
Select tab checkbox and change text qualifier to {none}.
Click next
Set column data types to general, text, text
Click finish.
Excel auto imports the data the best it can when you open directly in excel. You lose flexibility/control when this happens. better to import and control yourself to get the fine adjustments you're looking for.
You end up with something like this:
By treating the numbers like text, the zero's don't get messed up.
By setting the text qualifier to none, the quotes don't get messed up.
Have you tried opening it via Text Import?
Got to Data tab > From Text (third form left on default)
You will have window similar to Text To Columns.
Select correct delimiter, remember to remove the quote sign from TExt Qualifier and mark all columns as text to avoid Excel autoformatting.
Step 1:
Step 2:
Step 3:
EXCEL TIP: TIME SAVING IN IMPORTING CSV FILES INTO EXCEL: If u pre-set your Text-To-Columns delimiter parameters correctly in EXCEL (eg specify tabs as the delimiter) and then copy and paste the CSV data, Excel will import the CSV paste directly into the correct columns without u having to going through the Text-To-Columns rigmarole. This was particularly time saving when i had to import hundreds of bank statements into Excel.
However if your Text-To-Columns delimiters are pre-specified incorrectly as e.g. comma and you are importing tab delimited files then excel will dump all the data into one column, and u will have to go through the time consuming process of converting Text-To-Columns for each statement.
EXCEL LOOKS TO THE EXISTING Text-To-Columns delimiters TO SEE IF IT CAN USE THOSE TO MAKE YOUR LIFE EASIER WHEN PASTING DATA
Hope that tip helps (It saved me several hours)

How to Get Data from CSV File and Send them to Excel Using Pentaho?

I have a tabular csv file that has seven columns and containing the following data:
ID,Gender,PatientPrefix,PatientFirstName,PatientLastName,PatientSuffix,PatientPrefName
2 ,M ,Mr ,Lawrence ,Harry , ,Larry
I am new to pentaho and I want to design a transformation that moves the data (values of the 7 columns) to an empty excel sheet. The excel sheet has different column names, but should carry the same data, as shown:
prefix_name,first_name,middle_name,last_name,maiden_name,suffix_name,Gender,ID
I tried to design a transformation using the following series of steps, but it gives me errors at the end that I could not interpret them.
What is the proper design to move the data from the csv file to the excel sheet in this case? Any ideas to solve this problem?
As #Brian.D.Myers mentioned in the comment you can use select values step. But here is how you do it step by step explanation.
Select all the fields from CSV file input step.
Configure the select values step as follows.
In the Content tab of Excel writer step click on Get fields button and fill the fields. Alternatively you can use Excel output step as well.

How to format time data when importing txt file to access using VBA?

I am importing txt file data into Access db using VBA using Transfer Text, however it read the first column as time and returns 09:11:00. How can I format the variables before or after importing the data? Thanks in advance!
data:
09:11,10
10:10,11
Sub Import()
DoCmd.TransferText acImportDelim, , "TheTable", "D:\T1.txt", True
End Sub
Before importing the data, I don't think there is a way for you to format the text since you import it all together at one go. If you need to, you may open up the file and read the text line by line to change its format.
After importing, if you need to use a formatted column of your table you can try CDATE and FORMAT function like below
CDATE(FORMAT(TheTable.field1, "dd:mm,yy"))
I assume your data is in Day:Month,Year format. If not, you can just change the format string accordingly.

Change data in OLE Unbound Excel worksheet in Access

I have an OLE UNBOUND object in one form, with a class Excel.Sheet.12
by clicking in it I can insert data as an Excel sheet, but now I want to fill some cells using information present in a table in the database (to keep updated the Oleunbound embedded excel sheet).
I know how to manipulate external Excel files, but I don't know how to manipulate this excel object (e.g. what do I have to declare to select the right object?)
Thanks!
Treat .Object property of its' control as Excel
Me.OLEUnboundControlNname.Object.ActiveSheet.Cells(1, 1) = "Here I am!"

Ms-Access trying to use "transfer text" to create a csv file with a unique filename

I am trying to use an automated macro to export a Ms-Access table to a csv file. I want the destination file to have a unique name, and I reckoned that using now()yyyymmddhhnn would be a good way to achieve this.
I have got transfer text working ok from my macro, and I have set up an export file spec for the transfer.
I am using ="C:\batchfile_" & Format(Now(),"yyyymmddhhnn") & ".csv" in the filename argument in the macro. This bit works.
But when I try to run the macro, it tells me that the filename doesn't exist and then the export doesn't complete. I am not sure why this is, but I think it is because the export file specification is expecting the destination file to have the same filename and column structure as the source table.
Does anyone know a way around this?
Eric
This is very old thread, I am posting my solution so that it may be usefull for some one else
transfer text works fine, as long as variables are supplied properly, you can check for other options other than filename, datasource alternatively create using file open statement
by opening text file and convert recordset data into CSV format.