+ Reply to Thread
Results 1 to 2 of 2

Chart creation in Shared Workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    09-11-2015
    Location
    Hamilton, ON Canada
    MS-Off Ver
    2013
    Posts
    32

    Chart creation in Shared Workbook

    Hello,

    I have a Userform that generates a Chart on a sheet, then using the method of creating a GIF file from that Chart, vba then places the GIF file into a Image place holder on the Userform. However, when the workbook is Shared, creating charts is not possible. To get around this I turn off sharing while the chart is being generated, then turn on sharing once the operation is complete. I can only use this method if no one else has the workbook open and do not prefer to do it this way. I want to pass the chart to another workbook called "TempChartWB.xlsx" and create the GIF file from the temporary workbook. Is there a way to modify the following code to do this?

    I also attached a screen shot of the Userform below.

    Private Sub cbGetChart_Click()
    If txbBinNumber1.Text = "" Then
    MsgBox "Please Enter a Bin Number", vbInformation, "Store Keeper"
    txbBinNumber1.SetFocus
     Exit Sub
     End If
    'Turn off WORKBOOK SHARING so chart can be created
    If ActiveWorkbook.MultiUserEditing Then
            Application.DisplayAlerts = False
            ActiveWorkbook.ExclusiveAccess
            Application.DisplayAlerts = True
    End If
    
    'Get the year for which the chart is to be generated
    Dim ListYear As Integer
    ListYear = cmbYear.ListIndex
    Sheet19.Range("E1").Value = DateAdd("yyyy",[ListYear], Sheet19.Range("D1").Value)
     
    'Declaration
     Dim Mychart As Chart
     Dim ChartData1 As Range
     Dim ChartData2 As Range
     Dim ChartIndex As Integer
     Dim ChartName1 As String
     Dim ChartName2 As String
     Dim PartType1 As Range
     Dim PartType2 As Range
     Dim CostUnits1 As String
     Dim CostUnits2 As String
     Dim ws As Worksheet
     Set ws = Worksheets("Sheet19")
     
     'Activate Sheet 19
     Worksheets("Sheet19").Activate
    Set ChartData1 = ActiveSheet.Range("SheetData1")
    Set ChartData2 = ActiveSheet.Range("SheetData2")
    ChartName1 = txbBinNumber1.Value
    ChartName2 = txbBinNumber2.Value
    
    Application.ScreenUpdating = False
    
    'Write the values in textboxes to cells on sheet19
      ws.Cells(2, 6).Value = Me.txbBinNumber1
      ws.Cells(3, 6).Value = Me.txbBinNumber2
      
    'Write the value of cell S2 in sheet19 to textbox
      txbSumRng1.Text = Sheets("sheet19").Range("S2")
    'Look up the cost of the part and calculate to usage cost
      If txbBinNumber1.Value > "" Then
      CostUnits1 = Application.WorksheetFunction.VLookup(txbBinNumber1.Value, Sheets("Sheet1").Range("Sheet1Rng"), 14, False)
      txbCostRng1.Value = "$" & CostUnits1 * txbSumRng1.Value
      End If
    'Look up the cost of the part and calculate to usage cost
      txbSumRng2.Text = Sheets("sheet19").Range("S3")
      If txbBinNumber2.Value > "" Then
      CostUnits2 = Application.WorksheetFunction.VLookup(txbBinNumber2.Value, Sheets("Sheet1").Range("Sheet1Rng"), 14, False)
      txbCostRng2.Value = "$" & CostUnits2 * txbSumRng2.Value
      End If
      
    'Pick the chart type to be displayed and place it on the active sheet 19
    If OptionButton1 = True Then
    Set Mychart = ActiveSheet.Shapes.AddChart(xlBar).Chart
    End If
    
    If OptionButton2 = True Then
    Set Mychart = ActiveSheet.Shapes.AddChart(xlXYScatterLines).Chart
    End If
    
    If OptionButton3 = True Then
    Set Mychart = ActiveSheet.Shapes.AddChart(xl3DColumnClustered).Chart
    End If
    
    On Error Resume Next
    'Create the chart
     Mychart.SeriesCollection.NewSeries
     Mychart.SeriesCollection(1).Name = ChartName1
     Mychart.SeriesCollection(1).Values = ChartData1
     Mychart.SeriesCollection(1).XValues = ActiveSheet.Range("Month")
     Mychart.ChartTitle.Caption = "Sign Out Part Frequency"
     Mychart.Parent.Width = 570
     Mychart.Parent.Height = 250
     Set PartType1 = [Bin_Type_LBL]
     frmChartStats.Label1.Caption = Application.WorksheetFunction.VLookup(txbBinNumber1, PartType1, 3, False)
     
    If txbBinNumber2 <> "" Then
    
    On Error Resume Next
    
     Mychart.SeriesCollection.NewSeries
     Mychart.SeriesCollection(2).Name = ChartName2
     Mychart.SeriesCollection(2).Values = ChartData2
     Set PartType2 = [Bin_Type_LBL]
     frmChartStats.Label2.Caption = Application.WorksheetFunction.VLookup(txbBinNumber2, PartType2, 3, False)
    End If
    
    
    'Create a GIF image of the chart
    Dim imageName As String
     imageName = Application.DefaultFilePath & Application.PathSeparator & "TempChart.gif"
     
     Mychart.Export Filename:=imageName, FilterName:="GIF"
    'Delete the chart from Sheet 19
     ActiveSheet.ChartObjects(1).Delete
     
     Application.ScreenUpdating = True
    'Load the GIF image into a image place holder on the userform
     frmChartStats.Image1.Picture = LoadPicture(imageName)
    '
    'Turn on WORKBOOK SHARING
      If Not ActiveWorkbook.MultiUserEditing Then
            Application.DisplayAlerts = False
            ActiveWorkbook.SaveAs ActiveWorkbook.Name, accessmode:=xlShared
            Application.DisplayAlerts = True
    End If
     
    
    End Sub

    Frequency Chart.jpg


    Thanks for the help!

    BigD

  2. #2
    Registered User
    Join Date
    09-11-2015
    Location
    Hamilton, ON Canada
    MS-Off Ver
    2013
    Posts
    32

    Re: Chart creation in Shared Workbook

    Anyone????

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Convert Chart Creation Macro to Stacked Column Chart
    By JBeaucaire in forum Excel Charting & Pivots
    Replies: 6
    Last Post: 09-24-2014, 01:08 PM
  2. Replies: 0
    Last Post: 04-10-2014, 03:31 AM
  3. use existing creation date of workbook with newly created .saveas workbook
    By dwr0211 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-04-2011, 12:42 PM
  4. Bar chart creation
    By illinge in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 10-14-2009, 11:50 AM
  5. Chart creation in VBA
    By Lewis1 in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 07-28-2009, 05:39 AM
  6. Chart Creation
    By Hoopsah in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 08-21-2007, 08:02 AM
  7. how do I chart something if my workbook is "shared" ?
    By tgc-inc in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 12-02-2005, 06:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1