.AddShape not appearing when I want it to (vba)

tygrrboi

Well-known Member
Joined
Sep 8, 2015
Messages
1,196
Why does my screen not update to show my shape after I create it?

Code:
Sub FillBase()

Dim TList As Integer, weekdaycol As Integer, weekday As Integer, reff As Integer, refs As Worksheet, ws As Worksheet, ClassesSet As Integer
reff = 5
Set refs = Sheets("Sheet1")
Set ws = Sheets("Sheet2")
ws.Select
ActiveWindow.ScrollRow = 1


[COLOR=#ff0000]Call Commands.Create_Shape[/COLOR]
[COLOR=#ff0000]DoEvents[/COLOR]




Application.ScreenUpdating = False


ws.Columns("A:AF").Hidden = False


Call ClearWeek
For weekday = 5 To 169 Step 41
    TList = 3
    weekdaycol = 2
    While refs.Range("A" & TList) <> ""
        ws.Cells(weekday - 1, weekdaycol) = refs.Range("A" & TList)
        ws.Cells(weekday + 18, weekdaycol) = refs.Range("A" & TList)
        ws.Cells(weekday - 2, weekdaycol) = refs.Range("B" & TList)
        Call FillWeekday(TList, weekdaycol, refs, ws, reff, weekday - 5)
        TList = TList + 1
        weekdaycol = weekdaycol + 1
    Wend
    reff = reff + 2
Next weekday


If weekdaycol <= 31 Then
    Range(Columns(weekdaycol), Columns(31)).Hidden = True
End If
Call FillInClass
Call EC.Input_All_Classes
Call Levels
Sheets("PB").Range("KZ1:LJ40").Replace "x", "", xlWhole
ws.Select
Call Lunches
Application.ScreenUpdating = True


[COLOR=#ff0000]Call Commands.Delete_Shape[/COLOR]
[COLOR=#ff0000]DoEvents[/COLOR]




If ws.Range("AJ1") = True Then
    ClassesSet = MsgBox("Are there changes?", vbYesNo)
Else
    ClassesSet = vbYes
    ws.Range("AJ1").Value = True
End If
If ClassesSet = vbYes Then Call Group_Classes(ws)




[COLOR=#ff0000]Call Commands.Create_Shape[/COLOR]
[COLOR=#ff0000]DoEvents[/COLOR]


Application.ScreenUpdating = False
Call A_Prep_For_All
Application.ScreenUpdating = True


[COLOR=#ff0000]Call Commands.Delete_Shape[/COLOR]
[COLOR=#ff0000]DoEvents[/COLOR]


End Sub

Shape code

Code:
Sub Create_Shape()Dim MyShape As Object


Set MyShape = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 10, 10, 800, 600)


With MyShape
    .Name = "Wait"
    With .Line
        .ForeColor.RGB = RGB(255, 255, 0)
        .Weight = 3
    End With
    With .Fill
        .ForeColor.RGB = RGB(254, 255, 180)
        .Transparency = 0
        .Solid
    End With
    With .TextFrame
        .Characters.Text = "Schedule is being created." & vbNewLine & vbNewLine & vbNewLine & vbNewLine & vbNewLine & "Please be patient..."
    
        .Characters(1, 30).Font.Color = RGB(0, 0, 0)
        .Characters(30, 70).Font.Color = RGB(128, 128, 128)
        .Characters.Font.Bold = True
        .Characters(1, 70).Font.Size = 24
        .Characters.Font.Name = "Helvetica"
        .HorizontalAlignment = xlHAlignCenter
        .VerticalAlignment = xlVAlignCenter
    End With
End With


DoEvents
End Sub

I am confused :(
 
Last edited:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
What is the word "Commands" supposed to be for in front of the subs name when you are calling it?

Code:
Call [COLOR="#FF0000"]Commands.[/COLOR]Create_Shape
 
Upvote 0
Commands is the name of the module that the function Create_Shape is in. It is a different module than the function that is calling it is in.
 
Last edited:
Upvote 0
Try removing it i.e. test with

Code:
Sub FillBase2()

Dim TList As Integer, weekdaycol As Integer, weekday As Integer, reff As Integer, refs As Worksheet, ws As Worksheet, ClassesSet As Integer
reff = 5
Set refs = Sheets("Sheet1")
Set ws = Sheets("Sheet2")
ws.Select
ActiveWindow.ScrollRow = 1


Call Create_Shape
DoEvents


ws.Columns("A:AF").Hidden = False


End Sub

in a different module to the Create_Shape macro does the shape appear on Sheet2?
 
Last edited:
Upvote 0
I am certain that the shape is successfully created because I have tried leaving off one of the Delete_Shape functions (tested twice once the first time its called, and again the second time its called) and the shape remained on Sheet 2.

What I dont understand is why the screen isnt updating to show the shape while the rest of the code following it runs in the background. (it takes several seconds to complete things like FillInClass, Input_All_Classes, and Levels)


 
Upvote 0
Are you selecting a sheet in one of the other subs that you haven't posted?
 
Upvote 0
I didn't ask about activate I asked if you selected them.
When you step through the code using F8 is the sheet in view always Sheets("Sheet2")?
 
Upvote 0
I double checked. No cells on other worksheets are actually being selected. One of the functions does change the value of a cell in a different worksheet but I do not activate the worksheet or select the cell to do so. I just use something like Sheets("Sheet3").Range("X4") = "X" for example... Does that count as selecting a sheet?
 
Upvote 0

Forum statistics

Threads
1,216,120
Messages
6,128,948
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top