سلام
با کمک دوستان کد هایی رو در VBA نوشتم که در سیستم خودم که ویندوز 7 , 64 بیتی هست کاملا درست عمل میکنه ولی در ویندوز 32 بیتی و XP جواب نمیده . در واقع این کد نویسی ها رو انجام دادم تا برای همه موثر باشه چه کنم تا این مشکل حل بشه ! ؟
تصویر خطایی که تو XP میده بعد اصلا صفحه کدنویسی VBA دیگه باز نمیشه تو اون فایل
برای مثال در کد زیر که برای پروتکت کردن خودکار بر اساس یوزر نیم سیستم می باشد . تو اینترنت گشتم این مورد رو دیدم . شما به بینید این کد نویسی جواب میده ؟
کد PHP:
Option Explicit
If VBA7 Then
Declare PtrSafe Function WNetGetUser Lib "mpr.dll" _
Alias "WNetGetUserA" (ByVal lpName As String, _
ByVal lpUserName As String, lpnLength As Long) As Long
Else
Private Declare Function WNetGetUser Lib "mpr.dll" _
Alias "WNetGetUserA" (ByVal lpName As String, _
ByVal lpUserName As String, lpnLength As Long) As Long
End If
Const NoError = 0 'The Function call was successful
Public Function GetUserName() As String
' Buffer size for the return string.
Const lpnLength As Integer = 255
' Get return buffer space.
Dim status As Integer
' For getting user information.
Dim lpName, lpUserName As String
' Assign the buffer size constant to lpUserName.
lpUserName = Space$(lpnLength + 1)
' Get the log-on name of the person using product.
status = WNetGetUser(lpName, lpUserName, lpnLength)
' See whether error occurred.
If status = NoError Then
' This line removes the null character. Strings in C are null-
' terminated. Strings in Visual Basic are not null-terminated.
' The null character must be removed from the C strings to be used
' cleanly in Visual Basic.
lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)
Else
' An error occurred.
GetUserName = "Unable to get the name."
GoTo lbl_Exit
End If
' Display the name of the person logged on to the machine.
GetUserName = lpUserName
lbl_Exit:
Exit Function
End Function
|
اخطار: این یک موضوع قدیمی است به دلیل قدیمی بودن موضوع، ممکن است برخی فایل های ضمیمه به درستی کار نکنند. لطفا در صورت عدم ضرورت، از بالا آوردن موضوعات قدیمی خودداری نمایید. |
|
علاقه مندی ها (Bookmarks)