Search code examples
excelvbatouchscreen

Excel w/vba Program not coming to foreground at PC start Windows10 touchscreen


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 .


Solution

  • 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" ()

    I used a few forms also and some other variables to track pc system restarts