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 13th, 2002, 04:19 AM   #1
W. Baumann
New Member
 
Join Date: May 2002
Posts: 4
Default

Excel Automation Problem

(Excel 2000, Automation from Access 2000, Windows 2000 Professional)

Via Automation I format column X as following:

...
objActiveWkb.Worksheets(1).Range("X:X").Select
objXL.Application.Selection.NumberFormat = "#,##0.00"
objXL.Application.Selection.HorizontalAlignment = xlRight
...

Adjusting the horizontal alignment worked fine.
Setting the thousand separator does not work,
neither does the decimal separator completely.

The result looks like:
Saldo-EUR
-224107,39
-14243,97
-13030,46
-3228,9
-45136,95
-3648,51
-4971,6
-3404,26
...

Note the missing thousand separators ("." in some parts of Europe).
Note the missing "0" in eg -3228,9 (should be: -3228,90).

Manually checking the format within Excel shows that
setting the format did happen, but Excel fails to display
the new format.

Exactly the same lines of code worked in other instances.

Pressing "F2" and then "Enter" causes the cell to be displayed
correctly!

I would be very grateful for any suggestions.
Thanks in advance, Wilfried Baumann
W. Baumann is offline   Reply With Quote
Old May 13th, 2002, 04:27 AM   #2
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Maybe I'm mistaken, but it seems you are working with seperate objects?

objActiveWkb

objXL

Please clarify.

Thanks,
Tom

[ This Message was edited by: TsTom on 2002-05-13 03:28 ]
Tom Schreiner is offline   Reply With Quote
Old May 13th, 2002, 04:33 AM   #3
W. Baumann
New Member
 
Join Date: May 2002
Posts: 4
Default

You are right, the most recent version is:
(It should be the same object)

...
objActiveWkb.Worksheets(1).Range("X:X").NumberFormat = "#,##0.00"
objActiveWkb.Worksheets(1).Range("X:X").HorizontalAlignment = xlRight
...
W. Baumann is offline   Reply With Quote
Old May 13th, 2002, 04:45 AM   #4
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Hi W
This may or may not make a difference...
I could not duplicate the problem on my machine.
Can't hurt to try it out.



With objActiveWkb.Worksheets(1).Columns("X:X")
.NumberFormat = "#,##0.00;#,##0.00"
.HorizontalAlignment = xlRight
End With



Let me know if this helps or not.
If not, please post the complete procedure.
Thanks,
Tom


[ This Message was edited by: TsTom on 2002-05-13 03:50 ]
Tom Schreiner is offline   Reply With Quote
Old May 14th, 2002, 01:53 AM   #5
W. Baumann
New Member
 
Join Date: May 2002
Posts: 4
Default

'-------------------------------------------------------
Function FinalizeExcel(strWorkdir As String, _
strFilename As String, _
iNumTotal As Integer, _
iNumCustomers As Integer) As Boolean
'Examples:
' FinalizeExcel("c:", "Input.xls", 10, 5)
' FinalizeExcel("c:", "Test.xls", 20, 20)
Dim objXL As Object 'Object variable referencing Excel
Dim ExcelNotActive As Boolean
Dim objActiveWkb As Object
Dim i As Integer
Dim j As Integer
Dim iRes As Integer
Dim strRes As String
Dim strLine As String
Dim blRes As Boolean
Dim fs As Variant 'FileSystemObject
On Error Resume Next
'GetObject-Call without first argument returns a reference to
'an instance of the application. Otherwise an error is thrown.
'Debug.Print strFilename
Set objXL = GetObject(, "Excel.Application")
If Err.Number <> 0 Then ExcelNotActive = True
Err.Clear 'Delete Err-Objekt
On Error GoTo Err_FinalizeExcel
'Check for Excel:
DetectExcel
'Let object variables point to the correct file:
Set objXL = GetObject(strWorkdir & strFilename)
'Display Excel:
objXL.Application.Visible = True
objXL.Parent.Windows(1).Visible = True
'Process Excel file:
'Debug.Print objXL.Application.Name
'Debug.Print objXL.ActiveWorkBook.Name
Set objActiveWkb = objXL.Application.ActiveWorkbook
'Do some formatting:
objActiveWkb.Worksheets(1).Cells.Select
objXL.Application.Selection.Columns.AutoFit
objActiveWkb.Worksheets(1).Range("A:A").NumberFormat = "0"
objActiveWkb.Worksheets(1).Range("U:U").NumberFormat = "0"
objActiveWkb.Worksheets(1).Range("W:W").NumberFormat = "0"
objActiveWkb.Worksheets(1).Range("W:W").HorizontalAlignment = xlRight
objActiveWkb.Worksheets(1).Range("X:X").NumberFormat = "#,##0.00"
objActiveWkb.Worksheets(1).Range("X:X").HorizontalAlignment = xlRight
objActiveWkb.Worksheets(1).Range("X:X").Copy
objActiveWkb.Worksheets(1).Paste Destination:=objActiveWkb.Worksheets(1).Range("X:X")
objActiveWkb.Worksheets(1).Range("Y:Y").NumberFormat = "#,##0"
objActiveWkb.Worksheets(1).Range("Y:Y").HorizontalAlignment = xlRight
objActiveWkb.Worksheets(1).Range("Z:Z").NumberFormat = "#,##0"
objActiveWkb.Worksheets(1).Range("Z:Z").HorizontalAlignment = xlRight
objActiveWkb.Worksheets(1).Range("A2").Select
objActiveWkb.Worksheets(1).Name = "Customers"
objActiveWkb.Worksheets(1).Select
objActiveWkb.Sheets.Add after:=objActiveWkb.Worksheets(objActiveWkb.Worksheets.Count)
objActiveWkb.Worksheets(2).Name = "Non-Customers"
objActiveWkb.Worksheets(1).Select
'The first row contains the headers:
objActiveWkb.Worksheets(1).Rows("1:1").Select
objXL.Application.Selection.Copy
'Copy headers to second sheet:
objActiveWkb.Worksheets(2).Paste
'The customers should remain on sheet 1
'Non-customers should be copied to sheet 2:
If (iNumTotal - iNumCustomers > 0) Then
'If there are non-customers:
objActiveWkb.Worksheets(1).Rows(CStr(iNumCustomers + 2) & ":" & CStr(iNumTotal + 1)).Select
objXL.Application.Selection.Cut
objActiveWkb.Worksheets(1).Range("A2").Select
objActiveWkb.Worksheets(2).Select
objActiveWkb.Worksheets(2).Range("A2").Select
objActiveWkb.Worksheets(2).Paste
End If
objActiveWkb.Worksheets(2).Select
objActiveWkb.Worksheets(2).Cells.Select
objXL.Application.Selection.Columns.AutoFit
objActiveWkb.Worksheets(2).Range("A2").Select
objActiveWkb.Worksheets(1).Select
objXL.Application.ActiveWindow.TabRatio = 0.307
'Save to new temporary file:
objActiveWkb.SaveAs Filename:=strWorkdir & "tmp.xls", FileFormat:=xlExcel9795
objActiveWkb.Close savechanges:=True
Set fs = CreateObject("Scripting.FileSystemObject")
'Copy temporary file to original file:
fs.CopyFile strWorkdir & "tmp.xls", strWorkdir & strFilename, True
'Delete temporary file:
fs.DeleteFile (strWorkdir & "tmp.xls")
'Debug.Print "Done"
Set objActiveWkb = Nothing
Set objXL = Nothing
FinalizeExcel = True
Exit Function
Err_FinalizeExcel:
MsgBox ("Error: " & Err.Number & " " & Err.Description)
End Function
W. Baumann is offline   Reply With Quote
Old May 14th, 2002, 02:38 AM   #6
W. Baumann
New Member
 
Join Date: May 2002
Posts: 4
Default

Problem solved!

Adding the following line solved the problem:
...
objActiveWkb.Worksheets(1).Range("X:X").FormulaR1C1 = objActiveWkb.Worksheets(1).Range("X:X").Value
...

The whole block now looks like:
...
objActiveWkb.Worksheets(1).Range("X:X").NumberFormat = "#,##0.00"
objActiveWkb.Worksheets(1).Range("X:X").HorizontalAlignment = xlRight
objActiveWkb.Worksheets(1).Range("X:X").FormulaR1C1 = objActiveWkb.Worksheets(1).Range("X:X").Value
...

Thanks for the comments, they helped me to
specify the problem better.

Regards, Wilfried
W. Baumann 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 04: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