यह सक्रिय विंडो के शीर्षक (VBA का उपयोग कर)
Option Explicit
Private Declare Function GetActiveWindow Lib "User32.dll"() As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Function ActiveWindowName()
Dim hWnd As Long
Dim lngRet As Long
Dim strText As String
hWnd = GetActiveWindow()
strText = String(100, Chr(0))
lngRet = GetWindowText(hWnd, strText, 100)
ActiveWindowName=strText
End Function
यह सक्रिय विंडो पर शीर्षक वापस आ जाएगी मिल जाएगा, लेकिन मुझे लगता है कि 100 अक्षरों की लंबाई पर्याप्त होगी।
इस कोड को एक ऐसा फ़ंक्शन देना चाहिए जो वर्तमान शीर्षक लौटाता है, और लंबाई के लिए सही ढंग से समायोजित करता है। (मैं वर्तमान में ग # स्थापित नहीं है, इसलिए मैं इस परीक्षण नहीं कर सकते):
[DllImport("user32.dll")]
static extern IntPtr GetActiveWindow();
[DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)]
static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
public static string GetActiveWindowText()
{
IntPtr hWind = GetActiveWindow();
// Allocate correct string length first
int length = GetWindowTextLength(hWnd);
StringBuilder sb = new StringBuilder(length + 1);
GetWindowText(hWnd, sb, sb.Capacity);
return sb.ToString();
}
फिर आप स्ट्रिंग परीक्षण करने के लिए देखने के लिए इसमें क्या है सक्षम होना चाहिए। वीबीए उदाहरण में, =ActiveWindowName()
में ए 1Microsoft Excel - Book1
क्या मैं पूछ सकता हूं कि आपको ऐसा करने की आवश्यकता क्यों है? – JMK
@ जेएमके मैं एक्सेल सेल पर इनपुट फोकस नहीं होने पर निष्पादित करने के लिए अपने पेस्ट विशेष कोड को प्रतिबंधित करना चाहता हूं। –
शायद 'Excel.Worksheet.ActiveCell = null' या' Excel.ActiveCell = null'। – RoadBump