MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old May 2nd, 2002, 06:36 PM   #1
Quinn
New Member
 
Join Date: May 2002
Posts: 6
Default

Hi,
I am writing a VBS to import the text into Excel. The problem is whenever my data is in the form of '01-7008', it imports into Excel as 'Jan-08'.

Please help.
Thanks
Quinn
Quinn is offline   Reply With Quote
Old May 2nd, 2002, 06:38 PM   #2
Qroozn
Board Regular
 
Join Date: Mar 2002
Location: Sydney/Brisbane , Australia
Posts: 539
Default

it is reading the format of your cell.
try chnaging the format of the escel it is importing to... and then importing text only.
Qroozn is offline   Reply With Quote
Old May 2nd, 2002, 06:42 PM   #3
Quinn
New Member
 
Join Date: May 2002
Posts: 6
Default

Can you show me how to do that?

Thanks.
Quinn is offline   Reply With Quote
Old May 2nd, 2002, 06:59 PM   #4
Qroozn
Board Regular
 
Join Date: Mar 2002
Location: Sydney/Brisbane , Australia
Posts: 539
Default

format the page you are importing to..

1. highlight the entire page. then goto format cells.... text.

2. i dont know what your code for your import is. but excel vba has code along the lines of paste xlvalueonly =true


(I am not the best person at excel(infact I'm one of the worst)). just try and expand from what ahs already been shown and from search results on previous posts.
Qroozn is offline   Reply With Quote
Old May 2nd, 2002, 07:13 PM   #5
Rocky E
Board Regular
 
Join Date: Feb 2002
Location: North Alabama, USA
Posts: 105
Default

Hi,
What Qroozn is saying is correct. If you wish to import text (that is what you are saying) you must first format the column or range for text. There are several ways to do that. For example highlight a cell or column or range then FORMAT->CELLS->TEXT. Now your import will work, but this must be done before the import.


_________________
Hope this helps!

Rocky

"Be not the first by whom the New are try'd,
Nor yet the last to lay the Old aside."
Alexander Pope (1688-1744).

[ This Message was edited by: Rocky E on 2002-05-02 18:14 ]
Rocky E is offline   Reply With Quote
Old May 3rd, 2002, 10:26 AM   #6
Quinn
New Member
 
Join Date: May 2002
Posts: 6
Default

Hi

Thanks for all the help
I tried that already. It didn't work.

In my vbs, I created the object, open the spread sheet, and import data from the database. So I can't set the format of the cell prior to import.

There must be a way to set the cell format in vbs, but I am sorta new to vbs, I don't know all the methods and properties yet.

Thanks.
Quinn is offline   Reply With Quote
Old May 3rd, 2002, 10:45 AM   #7
kkknie
Board Regular
 
Join Date: Apr 2002
Location: Greenwood, SC
Posts: 677
Default

I'm not quite sure what you mean by importing to excel from vbs (VBScript?), but here's some possibly useless info.

If the script creates a new excel spreadsheet, then you will may be able to refer to is like this:

Application.Workbooks("Book1").Sheets("Sheet1").Columns("F:F").NumberFormat = "@"

This command will format Book1, Sheet1, ColumnF to text from any other excel workbook. The trick will be figuring out what to use in place of (or before) application...

If you figure it out, I'd love to know since I am thinking of some applications of my own right now.

K
kkknie is offline   Reply With Quote
Old May 3rd, 2002, 11:11 AM   #8
Quinn
New Member
 
Join Date: May 2002
Posts: 6
Default

Hi kkknie,

Yes, I was trying to use VBScript to pull info from the database and spit it out onto an excel spreadsheet.

Your Info wasn't useless. Infact, IT WORKED.
That's what I need to know! the 'NumberFormat' property!

I am not sure what you mean by "figuring out what to use in place of (or before) application..."
But here is the script...


Option Explicit

Dim xlexport
Dim rowIndex
Dim Qty_Lookup
Dim Total_qty
Dim fiscal_yr

rowIndex = 1

Sub Initialize
Set xlexport = CreateObject("Excel.Application")
xlexport.Workbooks.Add
xlexport.Visible = vbTrue
fiscal_yr = datecyr(CATALOG_BIDS.BUDGETYEAR)
End Sub

Sub PageHeading
xlexport.ActiveSheet.Cells(rowIndex,"A").Value = "Product ID #"
xlexport.ActiveSheet.Cells(rowIndex,"B").Value = "Qty Ordered"
xlexport.ActiveSheet.Cells(rowIndex,"C").Value = "Unit"
xlexport.ActiveSheet.Cells(rowIndex,"D").Value = "Description"

rowIndex = rowIndex + 1

End Sub

Sub GroupHeader_CATALOG_ORDERS_PRODUCTID
Set Qty_Lookup = CreateSQLCursor
Qty_Lookup.sql = "Select sum(orderqty) qty from catalog_orders where budgetyear = '" & fiscal_yr & "' and productid = '" & CATALOG_ORDERS.PRODUCTID & "'"

Qty_Lookup.MoveNext
Total_qty = Qty_Lookup.qty
xlexport.ActiveSheet.Cells(rowIndex, "A").Value = CATALOG_ORDERS.PRODUCTID
xlexport.ActiveSheet.Cells(rowIndex, "B").Value = Total_qty
xlexport.ActiveSheet.Cells(rowIndex, "C").Value = PE_PROD_MSTR.PE_UNIT
xlexport.ActiveSheet.Cells(rowIndex, "D").NumberFormat = "@"
xlexport.ActiveSheet.Cells(rowIndex, "D").Value = PEDESC.DESC
rowIndex = rowIndex + 1
End Sub



THANKS A BUNCH!
Quinn is offline   Reply With Quote
Old May 3rd, 2002, 11:16 AM   #9
kkknie
Board Regular
 
Join Date: Apr 2002
Location: Greenwood, SC
Posts: 677
Default

Much thanks for you posting your code.

My problem was that I had never activated an excel application from VBS and wasn't sure if you used Application("Excel"). or Excel.Application or some such nonsense.

Using the CreateObject function clears everything up. It's always nice to learn something when trying to answer other people's questions.

K
kkknie is offline   Reply With Quote
Old May 3rd, 2002, 11:32 AM   #10
RogerC
Board Regular
 
Join Date: Mar 2002
Location: Phoenix, Arizona
Posts: 454
Default

On a similar subject... I have a column of dates in the format of 1/01/02. Excel won't let me change the format of this column. No matter what format I try to apply, it still reads the cells in the column as a date serial number (35649). I need it to see the data as text so that I can trim the month off each date. any thoughts?
RogerC is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 12:24 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes