With ActiveSheetPageSetup
CenterHorizontally = True
CenterVertically = True
End With以下代码可完美解决你的问题,其中,根据的窗体改下Userform1
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetSystemMetrics Lib "user32 " (ByVal nIndex As Long) As Long
Private Const SM_CXSCREEN = 0
Private Const SM_CYSCREEN = 1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOZORDER = &H4
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_NOSIZE = &H1
Private Sub UserForm_Activate()
Dim x As Long, y As Long
x = GetSystemMetrics(SM_CXSCREEN)
y = GetSystemMetrics(SM_CYSCREEN)
Dim hw As Long
hw = FindWindow(vbNullString, "Userform1")'此处的Userform1是你窗体的Caption
If hw <> 0 Then SetWindowPos hw, HWND_NOTOPMOST, (x - UserForm1Width) / 2, (y - UserForm1Height) / 2, 0, 0, SWP_NOSIZE Or SWP_NOZORDER Or SWP_SHOWWINDOW
End Sub‘此处的Userform1是你的窗体名称Sub test()
For i = 1 To ActiveDocumentTablesCount
With ActiveDocument
Range(Tables(i)Cell(3, 1)RangeStart, Tables(i)Cell(5, 3)RangeEnd)Select
End With
SelectionFontSize = 8
SelectionParagraphFormatAlignment = wdAlignParagraphCenter
Next
End Sub1、Label 控件不可以水平,上下居中
2、不过可以用 PictureBox 控件做到
3、拖动一个 PictureBox 控件到工程,并命名为 picTextShow,把 AutoDraw 设为 True,加上以下代码就可以实现:
Option Explicit Private Sub Form_Load() picTextShowCurrentX=(picTextShowScaleWidth-picTextShowTextWidth("要显示的文本"))/2 picTextShowCurrentY=(picTextShowScaleHeight-picTextShowTextHeight("要显示的文本"))
picTextShowPrint "要显示的文本" End Sub
这样文本就可以在框中间显示了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)