简体   繁体   English

将启用宏的工作簿另存为 .xlxs

[英]Saving Macro Enabled workbook as .xlxs

I've set up a worksheet with a Macro in that checks the formatting of various cells, and at the end saves it as a normal .xlxs spreadsheet in the users C: drive.我已经设置了一个带有宏的工作表,用于检查各种单元格的格式,最后将其保存为用户 C: 驱动器中的普通 .xlxs 电子表格。

The code I've been trying is我一直在尝试的代码是

Dim sheetName As String
Dim tempwb As Workbook
Dim currentworkbook As String
Dim currentformat As Long

    currentworkbook = ThisWorkbook.FullName
    currentformat = ThisWorkbook.FileFormat
    sheetname = "Risk Info"

    ThisWorkbook.Sheets(sheetName).Copy before:=tempwb.Sheets(1)
    ThisWorkbook.Sheets(sheetName).SaveAs Filename:="C:\xstreamv1\inbox\xstream_data_sheet.xlsx", FileFormat :=51
    tempwb.Close savechanges:=False

    ThisWorkbook.SaveAs Filename:=currentworkbook, FileFormat:=currentformat
    ActiveWorkbook.Close savechanges:=False

    ActiveWorkbook.Close False

When I run the Macro it does create the xlxs copy I want, but it also creates and opens copies of the sheet I'm working in, and then crashes for a while!当我运行宏时,它确实创建了我想要的 xlxs 副本,但它也会创建并打开我正在使用的工作表的副本,然后崩溃了一段时间!

Any advice would be much appreciated!任何建议将不胜感激!

Sorry about the poor layout of the question.很抱歉问题的布局不佳。 I've managed to fix it now, using advice from Cyboashu, and other forums I found.我现在已经设法修复它,使用来自 Cyboashu 和我找到的其他论坛的建议。 Fixed code is:固定代码为:

Sub DataCheck()
'
' To check that the data entered in XStream is correct
'

Dim sheetName As String
Dim startRow As Integer, startCol As Integer
Dim endRow As Long, endCol As Integer
Dim row As Integer, col As Integer
Dim RC As Range
Dim c As Integer
Dim x As Integer
Dim a As Double
Dim tempwb As Workbook
Dim currentworkbook As String
Dim currentformat As Long

Set tempwb = Workbooks.Add

currentworkbook = ThisWorkbook.FullName
cuurentformat = ThisWorkbook.FileFormat


sheetName = "Risk Info" 'Your sheetname

    startRow = 3 'start row for the loop
    endRow = 20

    c = 0

    ...

    If c = 0 Then

        ThisWorkbook.Sheets(sheetName).Copy before:=tempwb.Sheets(1)
        ThisWorkbook.Sheets(sheetName).SaveAs Filename:="C:\xstreamv1\inbox\xstream_data_sheet.xlsx", FileFormat:=51
        tempwb.Close savechanges:=False

    Else
        MsgBox "There were issues with " & c & " entries. See red cells"
    End If





End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM