.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:
I just use something like Sheets("Sheet3").Range("X4") = "X" for example... Does that count as selecting a sheet?

No it would be
Code:
Sheets("Sheet3").Select
Range("X4") = "X"

So Sheet2 is always in view when you step through using F8?
 
Last edited:
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
yeah.

I think it might have something to do with my positioning of Application.ScreenUpdating = (true and false) and DoEvents

because im not too sure how to use them correctly.
 
Upvote 0
It shouldn't really be if you aren't doing any selecting as the shape is there before you turn screenupdating off.

DoEvents just surrenders execution to the operating system.

You should be able to tell one way or another if it is the screenupdating by removing/commenting out the screenupdating and then as I have already stated stepping through the code using F8 watching what happens and when (if at all) the shape vanishes and then you will also then know exactly where in the codes the issue lies.
 
Upvote 0
I agree with you. The puzzling thing is when I step through the code with F8 (command shift i on mac) It works. The shape appears, the rest of the code cycles through while the shape remains and the sheets do not change. Finally the shape disappears at the appropriate place. Everything is perfect.

When not stepping through, the shape never appears. Is it perhaps that my computer is not fast enough for it to process the shape before it zooms on to screenupdating false?
 
Upvote 0
I have scrapped the idea of making, deleting and making a shape again and just decided to try toggling it between visible and not.

I thought this would help as it seemed like just making the shape not visible would be quicker to process than deleting or creating a new shape.

I was wrong. It still does not appear during the code.

I have no idea whats wrong? Has anyone had trouble with shapes and screenupdating before?
 
Upvote 0
Try
Code:
Application.Wait(Now + TimeValue("0:00:03"))
and see if it makes a difference.
 
Upvote 0
Yes between the shape call and the ScreenUpdating =False (where the DoEvents currently is)
 
Upvote 0
No luck.

I think because this is purely a cosmetic addition I am just going to give up on it. Thank you for your help though.
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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