format worksheet using VBA

jloyzaga

Board Regular
Joined
Mar 19, 2008
Messages
80
the crude code below I am using to create a worksheet and formatting it and its not working
what its supposed to do is create a workbook, format it to be all cells to contain text, aligned to TOP and Left, and then I want to paste to cell (A1) what is in the copyboard - running this via Quicktest Professional so it should be close to visualbasicscript (I can convert from vba I guess).

can anybody correct this?



Code:
[COLOR=#000080][B]Set[/B][/COLOR] oEngine [COLOR=#000000]=[/COLOR] [COLOR=#000080][B]CreateObject[/B][/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"Excel.Application"[/COLOR][COLOR=#000000])[/COLOR]
oEngine.Workbooks.Add
[COLOR=#000080][B]Set[/B][/COLOR] objSheet [COLOR=#000000]=[/COLOR] oEngine.Sheets.Item[COLOR=#000000]([/COLOR][COLOR=#800000]1[/COLOR][COLOR=#000000])[/COLOR]
oEngine.Sheets.Item[COLOR=#000000]([/COLOR][COLOR=#800000]1[/COLOR][COLOR=#000000])[/COLOR].[COLOR=#000080][B]Select[/B][/COLOR]
[COLOR=#000080][B]With[/B][/COLOR] ActiveWorkbook.Styles[COLOR=#000000]([/COLOR][COLOR=#800000]"Normal"[/COLOR][COLOR=#000000])[/COLOR].NumberFormat [COLOR=#000000]=[/COLOR] [COLOR=#800000]"@"[/COLOR]
[COLOR=#000080][B]End[/B][/COLOR] [COLOR=#000080][B]with[/B][/COLOR]
    [COLOR=#000080][B]With[/B][/COLOR] objSheet
                  [COLOR=#008000][I]' .Styles("Normal").NumberFormat = "@"[/I][/COLOR]
            .Name [COLOR=#000000]=[/COLOR] [COLOR=#800000]"AU-AAPSQLUAT005"[/COLOR]
            .HorizontalAlignment [COLOR=#000000]=[/COLOR] xlCenter
            .Range[COLOR=#000000]([/COLOR][COLOR=#800000]"A1:A1"[/COLOR][COLOR=#000000])[/COLOR].Text
            .Range[COLOR=#000000]([/COLOR][COLOR=#800000]"A1"[/COLOR][COLOR=#000000])[/COLOR].Value [COLOR=#000000]=[/COLOR] [COLOR=#800000]"dbo.chClient_vW "[/COLOR]
            .Range[COLOR=#000000]([/COLOR][COLOR=#800000]"A2"[/COLOR][COLOR=#000000])[/COLOR].Value [COLOR=#000000]=[/COLOR] [COLOR=#800000]"Test Start Time: "[/COLOR]
           [COLOR=#000080][B]End[/B][/COLOR] [COLOR=#000080][B]with[/B][/COLOR]    
[COLOR=#000080][B]Set[/B][/COLOR] objSheet [COLOR=#000000]=[/COLOR] oEngine.Sheets[COLOR=#000000]([/COLOR][COLOR=#800000]"AU-AAPSQLUAT005"[/COLOR][COLOR=#000000])[/COLOR]
 
I'll give it a try thanks!!!

I have this other issue and it is on a word doc - how would I post it?
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
it involves excel but all the info is in the document - essentially its a requirement to validate the data saved above using the paste function. so there is a matrix that aligns different cells in different worksheets and they should be the same. This needs to be coded within my automation script so compare scriptA.cell(A1) to scriptB.cell(A4) and the should be the same-
 
Last edited:
Upvote 0
A new topic added onto an old thread will easily get overlooked.

Start a new thread and give a detailed description of what you are looking for. It's way past bed time in Scotland. With a bit of luck the night shift from USA/Australia will have it solved by morning (my time).

Bertie
 
Upvote 0
this did it
Set x = CreateObject("Mercury.Clipboard")
Set xlsApp = CreateObject("Excel.Application")
xlsApp.Visible = True
Set xlsWorkBook = xlsApp.Workbooks.Open("C:\Users\........")
Set xlsWorkSheet = xlsApp.ActiveWorkbook.Worksheets(1)
xlsWorkSheet.Paste
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,241
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top