Solved

vba excell automation to visual studio express 2012 vb

Posted on 2013-11-30
5
478 Views
Last Modified: 2013-12-01
Hello  experts,
the next line Works just fine in vb6

objsheet.Range(Cells(12, c + 1), Cells(fi, c + 1)).HorizontalAlignment = xlCenter

but in visual studio 2012 express visual basic, it simply is not accepted.

What is the correct way to do this?

Regards,
0
Comment
Question by:rguillermo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39687305
Can you expand on 'simply not accepted',  please?
0
 
LVL 14

Expert Comment

by:Faustulus
ID: 39687308
Try
with objsheet
    Range(.Cells(12, c + 1), .Cells(fi, c + 1)).HorizontalAlignment = xlCenter
End With

Open in new window

0
 

Author Comment

by:rguillermo
ID: 39687386
GrahamSkan

the sentence:

    objsheet.Range(Cells(12, c + 1), Cells(fi, c + 1)).HorizontalAlignment = xlCenter

produces the message

    "Cells" is not declared. It may be inaccesible due to its protection level.


Faustulus

with objsheet
    Range(.Cells(12, c + 1), .Cells(fi, c + 1)).HorizontalAlignment = xlCenter
End With

returns message: An unhandled exception of type 'system.runtime.InteropServices.COMException' ocurred in MicrosoftVisualBasic.dll
Additional information to set the HorizontalAlignment property of the range class.

this sentence

objsheet.cells("a1:c10¨").selection()

does not work either.

What could be the problema?
0
 
LVL 14

Accepted Solution

by:
Faustulus earned 500 total points
ID: 39687463
I would try to properly declare the object and then change its properties:_

Dim objSheet As Worksheet
Dim Rng As Range

Set objSheet = ThisWorkbook.Sheets("Sheet1")
with objsheet
    Set Rng = Range(.Cells(12, c + 1), .Cells(fi, c + 1))
End With
Rng.HorizontalAlignment = xlCenter 

Open in new window


The error seems to be a known bug which is related to late binding, In your case I presume that objSheet is declared as an object rather than a worksheet, and perhaps that is all it takes. But setting up the range as well as the sheet should make sure that Excel understands your instruction at runtime.

You may like to read up about this error at this link.
0
 

Author Closing Comment

by:rguillermo
ID: 39689041
Thanks !!
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question