Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 将工作表保存到新的workboook中,但使用值而不是引用公式_Vba_Excel - Fatal编程技术网

Vba 将工作表保存到新的workboook中,但使用值而不是引用公式

Vba 将工作表保存到新的workboook中,但使用值而不是引用公式,vba,excel,Vba,Excel,所以我尝试创建一个工作簿,它使用初始数据工作表中的多个引用自动填充不同工作表中的单元格,以生成表单(预格式化工作表)。对于其中一个工作表,我需要将其作为自己的.xlsx工作簿保存在单独的网络驱动器上。到目前为止,我开发的代码创建了新工作簿,但所有单元格仍然包含引用原始工作簿的原始公式。在保存到新工作簿时,是否有方法将单元格转换为值?这是我的潜水艇。短暂性脑缺血发作 Private Sub SaveBidTab1_Click() ' Saves the BidTab in the Curren

所以我尝试创建一个工作簿,它使用初始数据工作表中的多个引用自动填充不同工作表中的单元格,以生成表单(预格式化工作表)。对于其中一个工作表,我需要将其作为自己的.xlsx工作簿保存在单独的网络驱动器上。到目前为止,我开发的代码创建了新工作簿,但所有单元格仍然包含引用原始工作簿的原始公式。在保存到新工作簿时,是否有方法将单元格转换为值?这是我的潜水艇。短暂性脑缺血发作

Private Sub SaveBidTab1_Click()
'   Saves the BidTab in the Current Year's Bid Tabs Folder in
'   Dave's Snapserver Construction Files

Dim BTFName As String   'this will be the name of the new file name saved in the Bid Tabs Folder
Dim BTFfolder As String 'This is the folder to save the form into
Dim BTFDate As String   'This is the date to choose which year's folder to use
Dim ProjectShortName As String  'This is the short name for the project for the file name
Dim NewBook As Workbook ' This is temp workbook that the new bid tab sheet will be saved as

If Worksheets("BidTab").Range("G12") = "" Then
    ans = MsgBox("This form is not ready to be saved", vbOKOnly, "Bid Tabs")
    Select Case ans
        Case vbOK
        Exit Sub
    End Select
End If

'Requests user to enter in short name for project
Msg = "Enter Project Short Name"
ProjectShortName = InputBox(Msg, "Save As")

' TRIAL is added here until project is compelted.
BTFName = "TRIAL " & Worksheets("Initial Entry").Range("B5") & " " & ProjectShortName & _
    " " & "Bid Tab Results" & " " & Worksheets("BidTab").Range("L5")
' Add in a cancle option to this msgbox
MsgBox BTFName
BTFDate = Year(Now())
BTFfolder = "M:\DotserverD\Daves Snapserver Files Construction Files\Bid Tabs\" & BTFDate _
    & "\County"
    Debug.Print BTFfolder
Set NewBook = Workbooks.Add
ThisWorkbook.Worksheets("BidTab").Copy Before:=NewBook.Sheets(1)

NewBook.SaveAs Filename:=BTFfolder & "\" & BTFName & ".xlsx", FileFormat:=xlOpenXMLWorkbook

End Sub
ThisWorkbook.Worksheets(“BidTab”)。之前复制:=NewBook.Sheets(1)

请将此置于上述声明之后:

With NewBook.Sheets(1).UsedRange
    .Value = .Value
End With

这将删除链接,只保留新工作表中的值。

我在一本类似的书中也有这样的内容。你可以简化它

Dim shShape As Shape
    For i = 1 To UBound(sheetNames)
        mSaveWorkbook.Sheets(i).Name = sheetNames(i)
        If mSaveWorkbook.Sheets(i).Shapes.Count > 0 Then
            For Each shShape In mSaveWorkbook.Sheets(i).Shapes
                If shShape.Type = msoFormControl Then
                    shShape.Delete
                End If
            Next shShape
        End If
    Next i
End If

你是说你想断开链接吗?请参阅断开链接函数否,我希望保留值并删除公式。然后粘贴特殊XLPasteValue。请看同样的问题:谢谢!这很有效。有没有办法将我在原始工作簿上的两个命令按钮设置为不可见,或者在保存时将它们一起删除?@Decoy26欢迎,很高兴知道它起作用了。要从工作表中删除控件,您可以跨越工作表的
形状
集合,检查其
.name
属性,并对其调用
.delete