Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Setup / May 2007

Tip: Looking for answers? Try searching our database.

Auto_Open one time

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vitalidade2@gmail.com - 24 May 2007 21:10 GMT
I'm relatively new to VBA and I'm trying to write a macro that will
Auto_Open on the first try and place a chart on the excel sheet.  I've
gotten Excel (v. 2003) to create and save the chart automatically when
you open the workbook, but the problem is that every time the workbook
is opened the chart is replicated.  How can keep the chart from
replicating.  In other words, how do I only open the chart
automatically upon opening the file one time?  Any advice is greatly
appreciated
Dave Peterson - 24 May 2007 22:14 GMT
Maybe you could just count how many charts are on that worksheet (is the chart
on a worksheet???).

If there's one, then you're done and get out?

Option Explicit
Sub auto_Open()

   With Worksheets("sheet1") '<-- change this
       If .ChartObjects.Count > 0 Then
           Exit Sub
       End If
   End With
   
   'code to make the chart
End Sub

You could look for the chart name, too.

Option Explicit
Sub auto_Open()
   Dim TestChartObj As ChartObject

   With Worksheets("sheet1") '<-- change this
       Set TestChartObj = Nothing
       On Error Resume Next
       Set TestChartObj = .ChartObjects("Chart 1")
       On Error GoTo 0
       
       If TestChartObj Is Nothing Then
           'create the chart
           MsgBox "create the chart here"
       End If
   End With
End Sub

If you ctrl-click on the chart, you can see the chartobject's name in the
namebox (to the left of the name box).

> I'm relatively new to VBA and I'm trying to write a macro that will
> Auto_Open on the first try and place a chart on the excel sheet.  I've
[quoted text clipped - 4 lines]
> automatically upon opening the file one time?  Any advice is greatly
> appreciated

Signature

Dave Peterson

vitalidade2@gmail.com - 25 May 2007 13:56 GMT
> Maybe you could just count how many charts are on that worksheet (is the chart
> on a worksheet???).
[quoted text clipped - 49 lines]
>
> Dave Peterson

I actually tried both of your Posts Dave and Gord. Thanks for all your
help I have successfully completed the task :)
Gord Dibben - 24 May 2007 23:02 GMT
Code your auto_open so's it looks for a flag in a cell.

The flag can be anything like a text string.........."qwerty"

If this flag is present, the auto-open will stop.

Private Sub Auto_Open()
       If Sheets("Sheet1").Range("a1").Value <> "qwerty" Then Exit Sub
       MsgBox "do the stuff"
End Sub

Gord Dibben  MS Excel MVP

>I'm relatively new to VBA and I'm trying to write a macro that will
>Auto_Open on the first try and place a chart on the excel sheet.  I've
[quoted text clipped - 4 lines]
>automatically upon opening the file one time?  Any advice is greatly
>appreciated
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.