Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vba excell automation to visual studio express 2012 vb

Posted on 2013-11-30
5
Medium Priority
?
480 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 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
New style of hardware planning for Microsoft Exchange server.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

722 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