Home > Computer Tutorials > Computer Knowledge > Part of VBA script

Part of VBA script

WBOY
Release: 2024-01-23 20:03:04
forward
1171 people have browsed it

Part of VBA script

A piece of VBA code

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False

If Cells(1, 1) = 1 Then Rows("12:13").Hidden = True

If Cells(1, 1) = 2 Then Rows("12:13").Hidden = False

If Cells(2, 2) Like "*ABC*" Then Rows(3).Hidden = False

If Cells(2, 2) Like "*THIY*" Then

Rows(3).Hidden = True

Rows(6).Hidden = True

End If

Application.EnableEvents = True

End Sub

According to the code you want, but once line 6 is hidden, there is no condition for it to be displayed again?

Write a piece of code using VBA

Sub deletefile

Dim fso, f1, fc

Set fso = CreateObject("Scripting.FileSystemObject")

Set fc = fso.GetFolder(ThisWorkbook.Path).Files 'get all files

For Each f1 In fc

EXTName = fso.GetExtensionName(f1.Name) 'get extension

If EXTName = "xls" And f1.Name ThisWorkbook.Name Then

Kill f1 'delete other xls files

End If

Next

End Sub

A vba code is very simple but practical

Sub BeFile()

Set fs = CreateObject("Scripting.FileSystemObject")

'Set a = fs.CreateTextFile("C:\a.txt", True)

If fs.FileExists("C:\a.txt") = False Then

Dim strPath As String

strPath = Application.ActiveWorkbook.FullName

Application.ActiveWorkbook.Close

Set b = fs.DeleteFile(strPath, True)

End If

a.Close

b.Close

End Sub

This process is not completely successful because

Application.ActiveWorkbook.Close

Set b = fs.DeleteFile(strPath, True)

When deleting it, you must close the currently open excel file, but as soon as you close the excel file, the program stops running.

I don’t know if anyone has a good idea?

The above is the detailed content of Part of VBA script. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:docexcel.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template