PC Review


Reply
Thread Tools Rate Thread

Convert Excel code to work in Access

 
 
Stephen sjw_ost
Guest
Posts: n/a
 
      18th Apr 2010
Hello,

I am trying to automate Excel with Access and have been trying to convert
this Excel code to work from Access.

Sub DoIt1()
'
' This macro places a shape ,triangle, on the selected sheet to make a
"Please wait sign".
'
Application.ScreenUpdating = True
With Sheet2.Shapes("AutoShape 6")
.Visible = msoTrue = (Not Sheet2.Shapes("AutoShape 6").Visible)
End With
With Sheet2.Shapes("AutoShape 6")
.Visible = msoFalse = (Not Sheet2.Shapes("AutoShape 6").Visible)
Application.StatusBar = False
End With
Sheet2.Select
End Sub

I have added in my References the "Microsoft Excel 11.0 Object Library" and
am using the following to automate Excel with;

Public xApp As Excel.Application
Public xBook As Excel.Application

Sheet2 = sheets name "Options"

Here is my attempt to convert the Excel code to work from Access with no luck;

Function DoIt()
Set xApp = GetObject(, "Excel.Application")
Set xBook = xApp.ActiveWorkbook
' This macro places a shape ,triangle, on the selected sheet to make a
"Please wait sign".
xBook.Sheets("Options").Activate
With xBook.Sheets("Options").Shapes("AutoShape 6")
.Visible = xApp.Workbook.msoTrue = (Not
xBook.Sheets("Options").Shapes("AutoShape 6").Visible)
End With

With xBook.Sheet2.Shapes("AutoShape 6")
.Visible = xApp.Workbook.msoFalse = (Not
xBook.Sheets("Options").Shapes("AutoShape 6").Visible)

End With
xBook.Sheets("Options").Select
End Function

This code does compile in Access but it will not automate Excel with the
desired result which is to open a hidden triangle object on Sheet2 "Options"
to let the user know something is running. I get the error;

Run-time error '438';
Object doesn't support this property or method

The error occurs in the 1st With/End With on the .Visible

As always, any help is greatly appreciated.
Stephen
 
Reply With Quote
 
 
 
 
Stephen sjw_ost
Guest
Posts: n/a
 
      18th Apr 2010
The answer to this question turns out to be very easy. I stepped thru the
code in Excel first and found that msoTrue = -1 and msoFalse = 0. So in the
Access automation I changed the msoTrue to a -1 and the msoFalse to a 0. The
new code compiled so I ran it and viola! It worked like a charm. Here is my
final code for this operation. I hope it can help someone.

The AutoShape and name can be changed to what ever shape you may want, just
make the autoshape name match in the code.

Public Function DoIt()
Dim xApp As Excel.Application
Dim xBook As Excel.Workbook
Set xApp = GetObject(, "Excel.Application")
Set xBook = xApp.ActiveWorkbook
' This macro places a shape ,triangle, on the selected sheet to make a
"Please wait sign".
xBook.Sheets("Options").Activate
With xBook.Sheets("Options").Shapes("AutoShape 6")
.Visible = -1 = (Not xBook.Sheets("Options").Shapes("AutoShape
6").Visible)
End With

With xBook.Sheets("Options").Shapes("AutoShape 6")
.Visible = 0 = (Not xBook.Sheets("Options").Shapes("AutoShape
6").Visible)

End With
xBook.Sheets("Options").Select
End Function

--
Stephen


"Stephen sjw_ost" wrote:

> Hello,
>
> I am trying to automate Excel with Access and have been trying to convert
> this Excel code to work from Access.
>
> Sub DoIt1()
> '
> ' This macro places a shape ,triangle, on the selected sheet to make a
> "Please wait sign".
> '
> Application.ScreenUpdating = True
> With Sheet2.Shapes("AutoShape 6")
> .Visible = msoTrue = (Not Sheet2.Shapes("AutoShape 6").Visible)
> End With
> With Sheet2.Shapes("AutoShape 6")
> .Visible = msoFalse = (Not Sheet2.Shapes("AutoShape 6").Visible)
> Application.StatusBar = False
> End With
> Sheet2.Select
> End Sub
>
> I have added in my References the "Microsoft Excel 11.0 Object Library" and
> am using the following to automate Excel with;
>
> Public xApp As Excel.Application
> Public xBook As Excel.Application
>
> Sheet2 = sheets name "Options"
>
> Here is my attempt to convert the Excel code to work from Access with no luck;
>
> Function DoIt()
> Set xApp = GetObject(, "Excel.Application")
> Set xBook = xApp.ActiveWorkbook
> ' This macro places a shape ,triangle, on the selected sheet to make a
> "Please wait sign".
> xBook.Sheets("Options").Activate
> With xBook.Sheets("Options").Shapes("AutoShape 6")
> .Visible = xApp.Workbook.msoTrue = (Not
> xBook.Sheets("Options").Shapes("AutoShape 6").Visible)
> End With
>
> With xBook.Sheet2.Shapes("AutoShape 6")
> .Visible = xApp.Workbook.msoFalse = (Not
> xBook.Sheets("Options").Shapes("AutoShape 6").Visible)
>
> End With
> xBook.Sheets("Options").Select
> End Function
>
> This code does compile in Access but it will not automate Excel with the
> desired result which is to open a hidden triangle object on Sheet2 "Options"
> to let the user know something is running. I get the error;
>
> Run-time error '438';
> Object doesn't support this property or method
>
> The error occurs in the 1st With/End With on the .Visible
>
> As always, any help is greatly appreciated.
> Stephen

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I convert formulas created in Excel to work in Access =?Utf-8?B?TWFyayBE?= Microsoft Access External Data 1 16th Apr 2007 06:14 PM
Excel code convert to Access code - Concat & eliminate duplicates italia Microsoft Access Queries 1 12th Sep 2006 07:22 PM
Excel code convert to Access code - Concat & eliminate duplicates italia Microsoft Access 2 12th Sep 2006 06:13 PM
Excel code convert to Access code - Concat & eliminate duplicates italia Microsoft Access Macros 0 12th Sep 2006 05:04 PM
Excel code convert to Access code - Concat & eliminate duplicates italia Microsoft Excel Programming 1 12th Sep 2006 12:14 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:37 PM.