延长名称框

我可以通过向右或向左拖动“点”来手动缩短或延长名称框 (位于公式栏的左侧)。 (这也会缩短或延长配方栏。)

我怎样才能做VBA的调整?

在这里输入图像说明

唷!!!!

你扔我的东西!!! :P

当我意识到有没有本地的方式来实现你想要的,我诉诸API的方式,但我再次失望,因为“名称框”只暴露WS_CHILDWINDOWWS_VISIBLECBS_DROPDOWNCBSAUTOHSCROLLCBS_HASSTRINGS 。 “点”甚至没有处理。

在这里输入图像说明

出于挫折感,我开始按照马克在回答中所提出的思路来思考。 Registry方式。 我花了20多分钟findregistry项。 但是,唉,这种喜悦也没有持续多久,当我意识到更改registry键没有任何效果,直到我重新启动Excel。

在这之后,只剩下一个Simulation of the mouse 。 如果不行的话,我会把我的笔记本电脑砸到地上。

我在一开始尝试了一些硬编码值,并对结果感到满意。 所以这里是最后的版本…

 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _ (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _ ByVal lpsz2 As String) As Long Private Declare Function SetCursorPos Lib "user32" _ (ByVal X As Integer, ByVal Y As Integer) As Long Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function GetWindowRect Lib "user32" _ (ByVal hwnd As Long, lpRect As RECT) As Long Private Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, _ ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) Private Const MOUSEEVENTF_MOVE = &H1 ' mouse move Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up Private Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move Private Type POINTAPI X As Long Y As Long End Type Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Dim pos As RECT Sub Sample() Dim hwndExcel As Long Dim hwndPanel As Long Dim hwndCombo As Long Dim dest_x As Long Dim dest_y As Long Dim cur_x As Long Dim cur_y As Long Dim Position As POINTAPI '~~> Get the handle of the Excel Window hwndExcel = FindWindow("XLMAIN", Application.Caption) If hwndExcel = 0 Then Exit Sub 'MsgBox "Excel Window Found" '~~> Get the handle of the Panel where the Name Box is hwndPanel = FindWindowEx(hwndExcel, ByVal 0&, "EXCEL;", vbNullString) If hwndPanel = 0 Then Exit Sub 'MsgBox "Excel Panel Found" hwndCombo = FindWindowEx(hwndPanel, ByVal 0&, "Combobox", vbNullString) If hwndCombo = 0 Then Exit Sub 'MsgBox "Excel Name Box Found" '~~> Retrieve the dimensions of the bounding rectangle of the '~~> specified window. The dimensions are given in screen '~~> coordinates that are relative to the upper-left corner of the screen. GetWindowRect hwndCombo, pos '~~> Get the approx location of the DOT. It is where the Combobox ends cur_x = pos.Right cur_y = pos.Top + 10 '~~> New Destination dest_x = cur_x + 500 '<~~ Change width here dest_y = cur_y '~~> Move the cursor to the specified screen coordinates of the DOT. SetCursorPos cur_x, cur_y Wait 1 '<~~ Wait 1 second '~~> Press the left mouse button on the DOT mouse_event MOUSEEVENTF_LEFTDOWN, cur_x, cur_y, 0, 0 '~> Set the new destination. Take cursor there SetCursorPos dest_x, dest_y '~~> Press the left mouse button again to release it mouse_event MOUSEEVENTF_LEFTUP, dest_x, dest_y, 0, 0 Wait 1 MsgBox "done" End Sub Private Sub Wait(ByVal nSec As Long) nSec = nSec + Timer While nSec > Timer DoEvents Wend End Sub 

说明

将此代码粘贴到一个模块中,然后从表单按Alt + F8 ,然后selectSample ,然后按ALT + R

在Excel 2010中testing

之前

在这里输入图像说明

在这里输入图像说明

由于在VBA Excel.Application没有NameBox对象,我认为在本地VBA中是不可能的。

你必须钻研注册。 registry项是

在这里输入图像说明

注意 :即使您设置了该值,为使其生效,您也必须closures并打开Excel。