Solved

vba excell automation to visual studio express 2012 vb

Posted on 2013-11-30
5
468 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

730 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