File win là file gì? Là win.ini đấy à?Các bác giúp em đoạn Code lấy toàn bộ dữ liệu trong file C:\Windows\win (file Configuration Setings) vào Excel, em xin cảm ơn!
Sub GetWinINI()
With Sheet2.QueryTables.Add(Connection:="TEXT;C:\Windows\win.ini", Destination:=Range("$A$1"))
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileColumnDataTypes = Array(1)
.Refresh BackgroundQuery:=False
End With
End Sub
Bình thường mà anh.Tôi thử chạy code thì nó thông báo thế này (tạm hiểu là không dùng code để lấy dữ liệu được):
Code thế nào mà không được vậy anh?Tôi thử chạy code thì nó thông báo thế này (tạm hiểu là không dùng code để lấy dữ liệu được):
Microsoft Excel has stopped working.
Hang on windows reports the prolem to Microsoft.
A problem caused the program to stop working correctly.
Windows will close the program and notify you it a solution is available.
View attachment 188502
Sub Test()
With CreateObject("Scripting.FileSystemObject")
With .OpenTextFile("C:\Windows\win.ini")
MsgBox .ReadAll
.Close
End With
End With
End Sub
Cảm ơn bạn, Code chạy đúng như mình mong muốn, bạn có thể giúp thêm mình vấn đề này nữa được không: đó là mình chỉ cần lấy mỗi thông tin sau dấu "=" của dòng CMCDLLNAME32=mapi32.dll mà không cần lấy các thông tin bên trên và bên dưới của dòng đó, xin cảm ơn!Bạn nhận file!!!
Chưa hiểu ý bạn lắm, bạn nhận lại file xem!!!Cảm ơn bạn, Code chạy đúng như mình mong muốn, bạn có thể giúp thêm mình vấn đề này nữa được không: đó là mình chỉ cần lấy mỗi thông tin sau dấu "=" của dòng CMCDLLNAME32=mapi32.dll mà không cần lấy các thông tin bên trên và bên dưới của dòng đó, xin cảm ơn!
#If VBA7 Then
Declare PtrSafe Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long
#Else
Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long
#End If
bạn cho mình xin file mẫu ví dụBạn có thể dùng hàm API GetProfileString:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms724366(v=vs.85).aspx
lpAppName = "Mail"
lpKeyName = "CMCDLLNAME32"
lpDefault = ""
Khai báo trong VBA:
TQNMã:#If VBA7 Then Declare PtrSafe Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long #Else Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long #End If