您好我遇到了这个问题“方法”SaveAs“对象'_Workbook'失败。但我不确定到底发生了什么。
我的代码的目的是从工作簿中复制工作表并将其以xlsb格式保存为sharepoint文件夹中的单个工作表。
Sub SheetSplit()
'
'Creates an individual workbook for each worksheet in the active workbook.
'
Dim wbDest As Workbook
Dim wbSource As Workbook
Dim sht As Object
Dim strSavePath As String
Dim sname As String
Dim relativepath As String
Dim TempWB As Workbook
Set wbSource = ActiveWorkbook
Sheet6.Copy
Set wbDest = ActiveWorkbook
sname = Sheet9.Range("I5") & ".xlsb"
relativepath = "C:\Users\" & Environ$("Username") & _
"\SharePoint\Open Project Transition Check - Doc\Project Status Summary\" & sname 'use path of wbSource
'wbDest.Sheets(1).Range("A1").Clear 'clear filename from new workbook cell A1
CurrentFormat = ThisWorkbook.FileFormat
Application.DisplayAlerts = False
ActiveWorkbook.CheckCompatibility = False
ActiveWorkbook.SaveAs Filename:=relativepath, FileFormat:=xlExcel12 _
, CreateBackup:=False
Application.Wait (Now + TimeValue("0:00:01"))
Application.DisplayAlerts = True
wbDest.Close False 'close the newly saved workbook without saving (we already saved)
'Next
MsgBox "Status Summary Saved"
End Sub
答案 0 :(得分:1)
好的,你的代码有很多错误,所以让我们清理它们。
在 Excel 2010
上进行测试<?php
$con=mysqli_connect("127.2.1.1","S837","887","D887");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$qid = $_POST['qid'];
$email = $_POST['email'];
$result = mysqli_query($con, "SELECT * FROM QVOTES WHERE QID = $qid AND EMAIL = '$email'");
if (!mysqli_num_rows($result) ){
if ($result = mysqli_query($con, "INSERT INTO QVOTES (QID, EMAIL) VALUES ($qid, '$email')")) {
mysqli_query($con, "Update QUESTIONS SET VOTES = VOTES +1 WHERE QID = $qid");
echo "Update successful";
} else{
echo "Update unsuccessful";
}
} else{
echo "null";
}
mysqli_close($con);
请参阅SaveAs
要节省服务器使用
Option Explicit Sub SheetSplit() '// Creates an individual workbook for each worksheet in the active workbook. Dim wbDest As Workbook Dim wbSource As Workbook Dim sht As Object Dim strSavePath As String Dim sname As String Dim relativepath As String Dim TempWB As Workbook Set wbSource = ActiveWorkbook Sheets.copy Set wbDest = ActiveWorkbook sname = Sheets("Sheet1").Range("I5").Text & ".xlsb" relativepath = "C:\Users\" & Environ$("Username") & _ "\Desktop\Temp\" & sname 'use path of wbSource Application.DisplayAlerts = False ActiveWorkbook.CheckCompatibility = False ActiveWorkbook.saveas FileName:=relativepath, _ FileFormat:=50, _ CreateBackup:=False Application.Wait (Now + TimeValue("0:00:01")) Application.DisplayAlerts = True '// close the newly saved workbook without saving (we already saved) wbDest.Close False MsgBox "Status Summary Saved" End Sub
仅供参考,只有当它是您网络上的本地服务器时才有效