EXCEL的ActiveWorkbook.SaveAs如果已有文件存在,如何不要示提示框,直接覆?application.displayalerts=false
'保存
application.displayalerts=true
要達成你的要求應該不難
1.利用Sheets集合
2.每個Sheet要存成一個檔案,則需要將檔案存成Excel 4.0模式
以下是程式碼
Sub test()
Dim rSheet As Object
For Each rSheet In Sheets
rSheet.Select
ChDir "C:\test" '假設檔案要存檔的地方
ActiveWorkbook.SaveAs Filename:=rSheet.Name, FileFormat:=xlExcel4
Next rSheet
End Sub
要在檔案要存檔的地方建立如C:\test的目錄
********************************************
Sub test()
Dim rSheet As Object
Dim OldWorkBook As String, rDir As String
Application.ScreenUpdating = False
On Error Resume Next
ActiveWorkbook.Save
OldWorkBook = ActiveWorkbook.Name
rDir = ActiveWorkbook.Path
For Each rSheet In Sheets
rSheet.Select
ChDir "C:\test"
ActiveWorkbook.SaveAs Filename:=rSheet.Name, FileFormat:=xlExcel4
Next rSheet
ThisWorkbook.Saved = True
Application.OnTime Now + Time("00:00:1"), "closewin"
Workbooks.Open Filename:=rDir & "\" & OldWorkBook
Application.ScreenUpdating = True
End Sub
Sub closewin()
ThisWorkbook.Close
End Sub
2008年5月10日
2008年4月28日
2008年4月27日
Creating DataTable ...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Table1 As DataTable
Table1 = New DataTable("Customers")
'新增 DataTable 物件
Dim Row1, Row2, Row3 As DataRow
'新增三 個 rows 物件 for the table
Try
Dim Name As DataColumn = New DataColumn("Name")
'開始
Name.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(Name)
Dim Product As DataColumn = New DataColumn("Product")
Product.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(Product)
Dim Location As DataColumn = New DataColumn("Location")
Location.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(Location)
Row1 = Table1.NewRow()
'declaring a new row
Row1.Item("Name") = "Reddy"
'filling the row with values. Item property is used to set the field value.
Row1.Item("Product") = "Notebook"
'filling the row with values. adding a product
Row1.Item("Location") = "Sydney"
'filling the row with values. adding a location
Table1.Rows.Add(Row1)
'adding the completed row to the table
Row2 = Table1.NewRow()
Row2.Item("Name") = "Bella"
Row2.Item("Product") = "Desktop"
Row2.Item("Location") = "Adelaide"
Table1.Rows.Add(Row2)
Row3 = Table1.NewRow()
Row3.Item("Name") = "Adam"
Row3.Item("Product") = "PDA"
Row3.Item("Location") = "Brisbane"
Table1.Rows.Add(Row3)
Catch
End Try
Dim ds As New DataSet
ds = New DataSet
'creating a dataset
ds.Tables.Add(Table1)
'adding the table to dataset
DataGrid1.SetDataBinding(ds, "Customers")
'binding the table to datagrid
End Sub
Dim Table1 As DataTable
Table1 = New DataTable("Customers")
'新增 DataTable 物件
Dim Row1, Row2, Row3 As DataRow
'新增三 個 rows 物件 for the table
Try
Dim Name As DataColumn = New DataColumn("Name")
'開始
Name.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(Name)
Dim Product As DataColumn = New DataColumn("Product")
Product.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(Product)
Dim Location As DataColumn = New DataColumn("Location")
Location.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(Location)
Row1 = Table1.NewRow()
'declaring a new row
Row1.Item("Name") = "Reddy"
'filling the row with values. Item property is used to set the field value.
Row1.Item("Product") = "Notebook"
'filling the row with values. adding a product
Row1.Item("Location") = "Sydney"
'filling the row with values. adding a location
Table1.Rows.Add(Row1)
'adding the completed row to the table
Row2 = Table1.NewRow()
Row2.Item("Name") = "Bella"
Row2.Item("Product") = "Desktop"
Row2.Item("Location") = "Adelaide"
Table1.Rows.Add(Row2)
Row3 = Table1.NewRow()
Row3.Item("Name") = "Adam"
Row3.Item("Product") = "PDA"
Row3.Item("Location") = "Brisbane"
Table1.Rows.Add(Row3)
Catch
End Try
Dim ds As New DataSet
ds = New DataSet
'creating a dataset
ds.Tables.Add(Table1)
'adding the table to dataset
DataGrid1.SetDataBinding(ds, "Customers")
'binding the table to datagrid
End Sub
2008年4月19日
2008年4月18日
HOW TO:辨識 Visual Basic HTML 字串中的文字
資料來源處:http://msdn2.microsoft.com/zh-tw/library/ms235379(VS.80).aspx
HOW TO:辨識 Visual Basic HTML 字串中的文字
這個範例會使用簡單的規則運算式 (Regular Expression) 移除 HTML 文件的標記。
範例
HTML 標記會與規則運算式 \<[^\>]+\> 相符,這表示:
字元 "<",之後接著 一或多個字元集合,不包括 ">" 字元,之後接著
字元 ">"。
這個範例會使用共用的 System.Text.RegularExpressions.Regex.Replace(System.String,System.String,System.String) 方法,以使用空字串取代標記規則運算式的所有符合項。
'''Removes the tags from an HTML document.
''' HTML text to parse.
'''The text of an HTML document without tags.
'''
Function GetTextFromHtml(ByVal htmlText As String) As String
Dim output As String = Regex.Replace(htmlText, "\<[^\>]+\>", "")
Return output
End Function
這個範例要求您必須使用 Imports 陳述式,匯入 System.Text.RegularExpressions 命名空間。如需詳細資訊,請參閱 Imports 陳述式。
HOW TO:辨識 Visual Basic HTML 字串中的文字
這個範例會使用簡單的規則運算式 (Regular Expression) 移除 HTML 文件的標記。
範例
HTML 標記會與規則運算式 \<[^\>]+\> 相符,這表示:
字元 "<",之後接著 一或多個字元集合,不包括 ">" 字元,之後接著
字元 ">"。
這個範例會使用共用的 System.Text.RegularExpressions.Regex.Replace(System.String,System.String,System.String) 方法,以使用空字串取代標記規則運算式的所有符合項。
'''
''' HTML text to parse.
'''
'''
Function GetTextFromHtml(ByVal htmlText As String) As String
Dim output As String = Regex.Replace(htmlText, "\<[^\>]+\>", "")
Return output
End Function
這個範例要求您必須使用 Imports 陳述式,匯入 System.Text.RegularExpressions 命名空間。如需詳細資訊,請參閱 Imports 陳述式。
2008年4月9日
訂閱:
文章 (Atom)