当前位置:网站首页>Some problems encountered in the development of Excel VBA, solutions, and continuous updates
Some problems encountered in the development of Excel VBA, solutions, and continuous updates
2022-07-28 14:31:00 【CDamogu】
Excel FAQ

Excel FAQ
- FAQ1
- 1. If you want to be in 64 Bit system used on , You must update the code in this project . Please check and update Declare sentence , And then use PtrSafe Attributes mark them
- 2. When the form mode is selected , Workbook file is opened but cannot be operated , How to solve ?
- 3.VB in ME How to understand ?
- 4.ListView usage
- 5.Excel Workbook appears “ This workbook contains links to one or more external sources that may be unsafe ”, How can I cancel this annoying prompt ?
- 6. In the process of developing windows, I encountered a phenomenon : When I open Excel After the form , The table enters the window normally , After closing through the close button in the upper right corner , The next time you open the form, you will directly enter the form , Instead of entering the window . How to solve ?
- FAQ2
- FAQ3
- FAQ4
- FAQ5
- FAQ6
- FAQ7
- FAQ8
FAQ1
1. If you want to be in 64 Bit system used on , You must update the code in this project . Please check and update Declare sentence , And then use PtrSafe Attributes mark them
stay →Declare after
add to →PtrSafe
The box PtrSafe Mark Declare
2. When the form mode is selected , Workbook file is opened but cannot be operated , How to solve ?
Suppose the form is Demo1
Enter form :
Application.Visible = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Demo1.Show
Show workbook :
Application.Visible = True
Application.DisplayAlerts = True
Application.ScreenUpdating = True
The question you will encounter above is : The workbook is opened but cannot be operated on , Because the focus is always in the window
terms of settlement :
Demo1.Show vbModeless
3.VB in ME How to understand ?
The code where the object is located , If it is a worksheet code, it represents the worksheet , If it is form code, it represents form
If your code is written in worksheets under , be me Represents this worksheet ;
If the code is written in workbook Inside me representative thisworkbook,;
If the code is written under the custom form , be me Represents this form .
for example :
Private Sub UserForm_Initialize()
Me.OptionButton1.Value = True
Me.OptionButton5.Value = True
Me.OptionButton8.Value = True
End Sub
4.ListView usage
Sub initListView()
With ListView1 ' initialization listview
.ColumnHeaders.Add , , "COUNTIF", 45, lvwColumnLeft
.ColumnHeaders.Add , , " Power curve ", 45, lvwColumnLeft
.ColumnHeaders.Add , , " Active correction 1", 50, lvwColumnCenter
.ColumnHeaders.Add , , " Active correction 2", 50, lvwColumnCenter
.ColumnHeaders.Add , , " Damping compensation ", 45, lvwColumnCenter
.ColumnHeaders.Add , , " High frequency gain ", 45, lvwColumnCenter
.ColumnHeaders.Add , , " filter ", 40, lvwColumnCenter
.ColumnHeaders.Add , , " Soft dead center ", 40, lvwColumnCenter
.ColumnHeaders.Add , , " Wheel speed ", 40, lvwColumnCenter
.ColumnHeaders.Add , , " Stabilizing filter ", 60, lvwColumnCenter
.ColumnHeaders.Add , , " Torque damping ", 45, lvwColumnCenter
.ColumnHeaders.Add , , " Motor control ", 48, lvwColumnCenter
.View = lvwReport ' Display in report format
.LabelEdit = lvwManual ' Make content uneditable
.FullRowSelect = True ' Allow the entire line to be selected
.Gridlines = True ' Show gridlines
.Sorted = True ' Sort
End With
End Sub
5.Excel Workbook appears “ This workbook contains links to one or more external sources that may be unsafe ”, How can I cancel this annoying prompt ?
The first reason for this phenomenon may be : When copying the worksheet, the connection of the macro is also copied , Connected to another workbook
data -> Edit connection You can see the linked external file , So how to disconnect ?
Delete the macro with link , Then open the edit link again , You can see that broken links are available .
open EXCEL, In turn, open “ data ” tab ——“ Connect ” Group ——“ Edit connection ”—— Start prompt —— Do not display this warning , But update links (O)
6. In the process of developing windows, I encountered a phenomenon : When I open Excel After the form , The table enters the window normally , After closing through the close button in the upper right corner , The next time you open the form, you will directly enter the form , Instead of entering the window . How to solve ?
In fact, after clicking the close button in the upper right corner , Just simply close the window , At this time, the table is running in the background , It's just not on the interface , When you open it again, you will find that the form file is directly transferred out , Then the solution is : Overload the close button function
1. heavy load - Add exit options , Description of the problem that cannot be solved
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Dim Msg As String
Msg = MsgBox("È·¶¨ÒªÍ˳öÂð?", vbQuestion + vbOKCancel, "Ìáʾ")
If Msg = vbCancel Then Cancel = True
'If CloseMode <> 1 Then Cancel = True
End Sub
2. heavy load - Shielding off button , Be able to solve the above problems , The close button is completely shielded ( Can't quit )
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode <> 1 Then Cancel = True
End Sub
3. collocation - Create a new function to close 、 Exit options
ThisWorkbook.Close
4. Completely shielded X Button ( Because mine is x64, therefore API I directly added PtrSafe)
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const WS_SYSMENU = &H80000
Private Sub UserForm_Initialize()
Dim hWnd As Long, lStyle As Long
hWnd = FindWindow(vbNullString, Me.Caption)
lStyle = GetWindowLong(hWnd, GWL_STYLE)
SetWindowLong hWnd, GWL_STYLE, lStyle And Not WS_SYSMENU
End Sub
FAQ2
Form display textbox Control cannot display decimals properly
textbox1= sheets(“sheet1”).range(“a1”).text
FAQ3
vba: Is it possible to textbox.text The content inside is forcibly converted to numeric type
Dim i As Integer
If IsNumeric(textbox.txt) Then
i=val(textbox.text)
end if
sheets(“sheet1”).range(“a1”).value = val(textbox.text) But first of all, make sure it's numbers
FAQ4
Use Excel+VBA Operate on Web pages
With CreateObject("internetexplorer.application")
.Visible = True
.Navigate "https://www.baidu.com/s?wd= Bullshit "
' Close page
'.Quit
End With
FAQ5
VBA Open the file selection box 、 Get the full path and file name of the file
'VBA Open the file selection box 、 Get the full path and file name of the file
Sub selectExcelfile()
Dim fileNameObj As Variant
Dim aFile As Variant ' Array , Extract filename fileName When using
' Open the file dialog box to return the file name , Is a full path file name , Its value may also be False, Therefore, the type is Variant
Dim fullName As String
Dim fileName As String ' from FileName Path name extracted from
Dim i As Integer
fileNameObj = Application.GetOpenFilename("Excel file (*.xls),*.xls")
' call Windows Open the file dialog
If fileNameObj <> False Then ' If you do not press “ Cancel ” key
aFile = Split(fileNameObj, "\")
fileName = aFile(UBound(aFile)) ' The last element of the array is the file name
fullName = aFile(0)
For i = 1 To UBound(aFile) ' Circular synthesis full path
fullName = fullName & "\" & aFile(i)
Next
Else
MsgBox " Please select a file "
End
End If
' obtain Excel The full path
allExcelFullPath = fullName
' obtain Excel file name
workbookName = fileName
End Sub
FAQ6
obtain A The last non empty cell of the column :
iRow=range("a65536").end(xlup).rowThe number of rows in the first column
col = Application.WorksheetFunction.CountA(Columns(1))
FAQ7
QueryTables.Add(Connection The following is how to use variables for file names ?
Try the following code , error . fileToOpen = Application.GetOpenFilename("Text Files (*.txt), *.txt") ActiveSheet.QueryTables.Add(Connection:="TEXT;fileToOpen", Destination:=Range("A1"))
answer :
Connection:="TEXT;" & fileToOpen,
FAQ8
How to close the form program automatically after running , It doesn't take up memory ?
There is code in the form , The function I want to achieve is when these codes are run , This form closes automatically , What is this code ?
Me.Hideunload me
边栏推荐
- Xcode编写SwiftUI代码时一个编译通过但导致预览(Preview)崩溃的小陷阱
- Excel VBA 开发过程中遇到的一些问题,解决方案,持续更新
- Multi level cache scheme
- Literature reading (245) roller
- 利用反射构建一棵菜单生成树
- [utils] fastdfs tool class
- Four ways to create thread pools
- Discrete logarithm problem (DLP) & Diffie Hellman problem (DHP)
- 2022 low voltage electrician examination questions and answers
- PowerDesigner creates a database model (conceptual model example)
猜你喜欢

2022 safety officer-a certificate operation certificate examination question bank simulated examination platform operation

天气这么热太阳能发电不得起飞喽啊?喽啊个头……

What is a spin lock? A spin lock means that when a thread attempts to acquire a lock, if the lock has been occupied by other threads, it will always cycle to detect whether the lock has been released,

文件批量重命名工具Bulk Rename Utility

QT self-made soft keyboard is the most perfect and simple, just like its own virtual keyboard

八、picker用法 下拉框选择效果

2022 melting welding and thermal cutting examination questions and online simulation examination

Leetcode 0143. rearrange linked list

草料二维码--在线二维码生成器

OKR与GRAD
随机推荐
Three cases of thread blocking.
Leetcode 1331. array sequence number conversion
How to effectively conduct the review meeting (Part 1)?
Websocket chat
Install mysql5.7.36 in CentOS
复制excel行到指定行
工厂模式和构造函数模式
Realization of chat room function
Redis sentinel mechanism
【Utils】ServletUtil
成为绿色数据中心新样板,东莞华为云数据中心是怎样炼成的?
八、picker用法 下拉框选择效果
Node file operation
Cv:: mat conversion to qimage error
九、uni-popup用法 下拉框底部弹窗效果
JMeter installation tutorial and login add token
Three methods to disassemble the rotation array
How does vos3000 send incoming calls to okcc
爆肝整理JVM十大模块知识点总结,不信你还不懂
十、时间戳