Forum Discussion

MolineZ's avatar
MolineZ
Copper Contributor
May 22, 2022

Excel Program not coming to foreground at PC start Windows10 touchscreen

Hoping to find some help here.

I have a windows10 pc with a touchscreen and no keyboard or mouse. I have an excel program that I want to start up everytime the pc is restarted. I used shell:startup to place a shortcut for the file in the folder and the system will start and open the file but it is in the background. I can click it from the tablet menu and it opens but i would like it to come to the foreground by itself. I did some testing and setup the exact same file into a nontouch screen laptop and the file opens perfect. Here is a sample of the simple vba code running on the file and some code I have tried to make it come to the foreground. 

private Sub Workbook_Open()

    Application.Caption = "Test System"

    Application.Wait (Now + 0.0001)

    'SendKeys "%{Tab}", True

    'ActiveWindow.Visible = True

    MsgBox "System Restarting", vbcritcal + vbSystemModal

End Sub

the two comment lines I have tried to make the program come to the foreground but they did not help, I tried them one at a time .

  • MolineZ's avatar
    MolineZ
    Copper Contributor

    MolineZ 

    I used this code to make it work, the sendkeys command had to be after a few lines of code to work other wise the program would not come to the foreground. AppActivate only gave me runtime error #5. 

    Private Sub Workbook_Open()

        restartct = Sheets("search").Cells(1, 13)

        If GetTickCount < 80000 Then

          restartct = restartct + 1

          Application.Wait (Now + 0.0001)

          Application.WindowState = xlMaximized

          frmBadinput.Label1 = "System Restarting"

          SendKeys "%{tab}"

          mdelay = 2

          frmBadinput.Show

        End If

        frmWelcome.Show

         Sheets("Search").Activate

         ActiveSheet.Cells(1, 13).Value = restartct

         ActiveSheet.Cells(5, 1).Select

         ActiveWindow.Zoom = 120

    End Sub

    macro#1

    Option Explicit

    Public Declare Function GetTickCount& Lib "kernel32" ()

Resources