Home > Software engineering >  Workbook VBA scripts how to save the modules work?
Workbook VBA scripts how to save the modules work?

Time:10-05


Excel VBA scripts as follows

ThisWorkbook. SaveAs

ActiveWorkbook. SaveAs

For the workbook save,

Remove the module workbook. Remove. After Item,

Workbook VBA scripts how to save the modules work?

CodePudding user response:

What do you mean? Didn't see,

CodePudding user response:

reference 1st floor Topc008 response:
what do you mean? Didn't see,


After removing the module running
ThisWorkbook. SaveAs or
ActiveWorkbook. SaveAs script

Still need to confirm when close the file save or cancel button at a time,

CodePudding user response:

After removing the module Settings thisworkbook. Saved=true, then exit the workbook won't appear save dialog...

CodePudding user response:

reference Topc008 reply: 3/f
after removing the module Settings thisworkbook. Saved=true, then exit the workbook won't appear save dialog...


The code is as follows:
6 (SUB)
'
ActiveWorkbook. Sheets (" 6 "). Select
Range (" A1: A1). Select
With the Application. The VBE varies. ActiveVBProject. VBComponents
. Remove. Item (" 6 ")
End With
ThisWorkbook. Saved=True
ThisWorkbook. SaveAs (" C: \ 6. XLS ")
'
End Sub

Results there is still a save dialog box, press save to remove module, according to not save does not remove the module,

CodePudding user response:

6 (SUB)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
This process can name the first character number?? !!!!!!!!! Let's change the

And this kind of circumstance should be without: ThisWorkbook Saved=True


CodePudding user response:

reference 5 floor Topc008 reply:
SUB 6 ()
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
This process can name the first character number?? !!!!!!!!! Change it


Process name is not important, the problem hasn't solved,

CodePudding user response:

Consider the following code:
 Sub Test () 
"' if you don't set DisplayAlerts=false, when the saveas, if there will be prompted to overwrite
Application. DisplayAlerts=False
Dim VBC
With the Application. The VBE varies. ActiveVBProject
For Each VBC. In VBComponents
If VBC. Name="module 1" Then
. VBComponents. Remove VBC 'just delete module 1
End the If
Next
End With
ThisWorkbook. SaveAs (" d: \ 6. XLS ")
Application. DisplayAlerts=True
End Sub




CodePudding user response:

The
reference 7 floor Topc008 response:
consider the following code:


Using VBA variable operating normally, after setting Application. After DisplayAlerts parameter to False files with the same cover save prompt disappear,

Close the file still play selection box, if you choose not to save will find module has not been removed, only choose save button to remove the module again,

CodePudding user response:

Workbook is closed if you don't save the changes to this: thisworkbook. Close false
Close to save the changes at the same time can be like this: thisworkbook. Close true

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Or do you get the complete code, post and see where the problem is (clear)

CodePudding user response:

references 9 f Topc008 response:
or do you get the complete code, post and see where the problem is (clear)


Whether thisworkbook. Close true or false, the file is closed, but modules are still has not been removed,


Sub my_6 ()
Range (" A1: A1). Select
With the Application. The VBE varies. ActiveVBProject. VBComponents
. Remove. Item (" my_6 ")
End With
ThisWorkbook. SaveAs (" D: \ 6. XLS ")

End Sub


The function of this code is removed in the XLS file my_6 module, and save as XLS file does not contain the module,

CodePudding user response:

Finally understand!!!!!! Not easy ah,
"My_6 module" is just a name, rather than the module name!!!!!! All the above code is invalid!!!!!

CodePudding user response:

The
reference 11 floor Topc008 reply:
"my_6 module" is just a name, rather than the module name!!!!!! All the above code is invalid!!!!!


My_6 is module name and delete the module, the process of the

CodePudding user response:

Refer to the following code:
 Sub test () 
' 'this example delete "module 1" pro_5 process of module
'to refer to: Microsot Visual Basic For Applications Extensibility 5.3
Dim VBC As VBComponent, iStart As Long, k As Long
The Set of VBC=ThisWorkbook. VBProject. VBComponents (" module 1 ")
K=VBC. CodeModule. ProcCountLines (" pro_5 vbext_pk_Proc) 'the process occupies the total number of rows
IStart=VBC. CodeModule. ProcStartLine (" pro_5 vbext_pk_Proc)
VBC. CodeModule. DeleteLines iStart, k
'to remove the processEnd Sub


CodePudding user response:

I tried this approach, the good,

Removal process after the line to keep left empty module,

Question whether can remove the whole module, and then save don't need to be confirmed,

CodePudding user response:

On the 14th floor mingxyzonline
reference response:
I tried this approach, the good,

Removal process after the line to keep left empty module,

Question whether can remove the whole module, and then save does not need to be confirmed,

Oh, still want to delete the module, the code above does not have? .
Ok, let me put a:

 Sub Test () 
"' this process on VBComponents (" sheet1"),
"' and add a module, its name is called" module 1 and save the exits, "
"' to open the workbook" module 1 "are detected, the began to run the code
"' on the workbook will automatically shut down, to find" module 1 "no!
Dim VBC As VBComponent
With ThisWorkbook. VBProject
For Each VBC. In VBComponents
If VBC. Name="module 1" Then
. VBComponents. Remove VBC 'just delete module 1
End the If
Next
End With
"' if the execution of the following statements does not want to appear when prompted, please restore the following comments section
"' Application. DisplayAlerts=False" 'blocking tip
ThisWorkbook. SaveAs "d: \ 6. XLS"
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • VBA
  • Related