首頁>職場>

先來看下效果:

上面的圖片瀏覽器是在Excel中做出來的。

具體的用的Image、CommandButton控制元件。

思路如下:

當首次執行窗體時,窗體中預設載入第一張圖片:

Private Sub UserForm_Initialize()

pat = ThisWorkbook.Path

Me.Image1.Picture = LoadPicture(pat & "\1.jpg")

n = 1

End Sub

'首頁

Private Sub CommandButton1_Click()

Me.Image1.Picture = LoadPicture(pat & "\1.jpg")

n = 1

End Sub

'上一頁

Private Sub CommandButton2_Click()

If n = 1 Then

Exit Sub

Else

n = n - 1

Me.Image1.Picture = LoadPicture(pat & "\" & n & ".jpg")

End If

End Sub

'下一頁

Private Sub CommandButton3_Click()

If n = 15 Then

Exit Sub

Else

n = n + 1

Me.Image1.Picture = LoadPicture(pat & "\" & n & ".jpg")

End If

End Sub

'尾頁

Private Sub CommandButton4_Click()

Me.Image1.Picture = LoadPicture(pat & "\15.jpg")

n = 15

End Sub

全部程式碼如下:

Public pat$, n%Private Sub UserForm_Initialize()pat = ThisWorkbook.PathMe.Image1.Picture = LoadPicture(pat & "\1.jpg")n = 1End Sub'首頁Private Sub CommandButton1_Click()    Me.Image1.Picture = LoadPicture(pat & "\1.jpg")    n = 1End Sub'上一頁Private Sub CommandButton2_Click()    If n = 1 Then        Exit Sub    Else        n = n - 1        Me.Image1.Picture = LoadPicture(pat & "\" & n & ".jpg")    End IfEnd Sub'下一頁Private Sub CommandButton3_Click()    If n = 15 Then        Exit Sub    Else        n = n + 1        Me.Image1.Picture = LoadPicture(pat & "\" & n & ".jpg")    End IfEnd Sub'尾頁Private Sub CommandButton4_Click()    Me.Image1.Picture = LoadPicture(pat & "\15.jpg")    n = 15End Sub

轉自:米宏Office

12
最新評論
  • 工作沒回報,還要繼續嗎?
  • 北大高材生,寫萬字長文給任正非提建議,為何卻被華為開除?