当前位置:网站首页>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
边栏推荐
- How did Dongguan Huawei cloud data center become a new model of green data center?
- 2022 safety officer-a certificate operation certificate examination question bank simulated examination platform operation
- 这3款在线PS工具,得试试
- Introduction to database system (5th Edition) supplementary exercises - Chapter 1 Introduction
- 一些企业数据平台建设的思考
- 为什么jq的匿名函数 外部可以访问到里面的方法
- ScottPlot入门教程:获取和显示鼠标处的数值
- 7.27 simulation summary
- Force deduction solution summary 1331 array sequence number conversion
- Alibaba, jd.com, Tiktok: push cloud to the heart of industry
猜你喜欢

成为绿色数据中心新样板,东莞华为云数据中心是怎样炼成的?

RSA encrypts data with private key and decrypts data with public key (not a signature verification process)

Another way of understanding the essence of Hamming code

Clickhouse distributed cluster construction

如何只降3D相机不降UI相机的分辨率

Leetcode 0142. circular linked list II

Alibaba, jd.com, Tiktok: push cloud to the heart of industry

@DS('slave') 多数据源兼容事务问题解决方案

Foundation of deep learning ---- GNN spectral domain and airspace (continuous improvement, update and accumulation)

Thesis study -- masked generative disintegration
随机推荐
Development and definition of software testing
HCIP第十二天
聊天室功能的实现
Custom Configuration Sections
Revised version | target detection: speed and accuracy comparison (faster r-cnn, r-fcn, SSD, FPN, retinanet and yolov3)
Why is it reverse to convert from other formats to BMP
Using reflection to build a menu spanning tree
[ecmascript6] proxy and reflection
2022 low voltage electrician examination questions and answers
Thrift 序列化协议浅析
TDengine 助力西门子轻量级数字化解决方案
如何有效进行回顾会议(上)?
2022年安全员-A证操作证考试题库模拟考试平台操作
[ecmascript6] modularization
Leetcode 0142. circular linked list II
多所“双一流”大学,保研预报名启动!
C# 获取当前路径7种方法
Copy excel row to specified row
Tdengine helps Siemens' lightweight digital solutions
Collaborative office tools: Online whiteboard is in its infancy, and online design has become a red sea