vbscript Unmerge&FillExcel - Macro

Unmerge&FillExcel - Macro

UnmergeFill.vb
Sub UnmergeFill()

Dim cell As Range, joinedCells As Range
Application.ScreenUpdating = False

For Each cell In ActiveWorkbook.ActiveSheet.UsedRange
    If cell.MergeCells Then
        Set joinedCells = cell.MergeArea
        cell.MergeCells = False
        joinedCells.Value = cell.Value
    End If
Next

Application.ScreenUpdating = True

End Sub

vbscript EAN13 Excel(前4位)

EAN13 Excel(前4位)

ean13.vb
Function EAN_13(Code As String) As String
    Dim s As String
    s = Code
    cs = 0
    
    For i = 1 To 12
        digit = Mid(s, i, 1) - "0"
        If i Mod 2 = 0 Then
          cs = cs + digit * 3
        Else
            cs = cs + digit * 1
        End If
    Next i

    cs = (10 - (cs Mod 10)) Mod 10
       
    EAN_13 = s & cs
End Function

vbscript gistfile1.vb

gistfile1.vb
'Pixel & Twip 的換算
Public Function pixelToTwip(ByVal pixel As Long) As Long
pixelToTwip = Screen.TwipsPerPixelX * pixel
End Function

'LoadMovie
Public Function loadMovie(moviePath As String)
ShockwaveFlash1.Movie = moviePath
End Function

vbscript gistfile1.vb

gistfile1.vb
'進行必要的屬性初始化
'對齊模式
ShockwaveFlash1.SAlign = "TL"
'禁用某些功能
ShockwaveFlash1.AllowFullScreen = True
ShockwaveFlash1.AllowNetworking = "all"
ShockwaveFlash1.AllowScriptAccess = "always"
'背景顏色,兩種語法等效
'ShockwaveFlash1.BackgroundColor = RGB(255, 255, 255)
ShockwaveFlash1.BGColor = "ffffff"
'相對路徑
ShockwaveFlash1.Base = "."
'是否使用裝置字體
ShockwaveFlash1.DeviceFont = False
'縮放模式:0=showAll,1=NoBorder,2=ExactFit,3=noScale
ShockwaveFlash1.ScaleMode = 3
'品質:Hgh,Low,AutoHigh,AutoLow,Medium,AutoMedium
ShockwaveFlash1.Quality2 = "high"
'透明模式:Window,Opaque,Transparent
ShockwaveFlash1.WMode = "window"
'是否消除鋸齒
ShockwaveFlash1.SeamlessTabbing = True

'表單數值初始化
movieWidth = 100 '寬度 in pixels
movieHeight = 100 '高度 in pixels
titleBarWidth = Form1.Width - Form1.ScaleWidth
titleBarHeight = Form1.Height - Form1.ScaleHeight
Form1.Width = pixelToTwip(movieWidth) + titleBarWidth
Form1.Height = pixelToTwip(movieHeight) + titleBarHeight

'播放影片
loadMovie App.Path + "\main.swf"

vbscript 关闭错误/结果显示

关闭错误/结果显示

Access Warnings
DoCmd.SetWarnings (False)

DoCmd.SetWarnings (True)

vbscript 使用HTTP传输文件

使用HTTP传输文件

HTTP File Transfer.vbs
'Does not have to be hardcoded like below, can be pulled from a text box or something
Dim strPostURL = "http://www.google.com"

        AddText("URL TO POST: " + strPostURL)

        Dim requestStream As Stream = Nothing
        Dim fileStream As FileStream = Nothing
        Dim uploadResponse As Net.HttpWebResponse = Nothing

        Try

            Dim uploadRequest As Net.HttpWebRequest = CType(Net.HttpWebRequest.Create(strPostURL), Net.HttpWebRequest)
            uploadRequest.Method = Net.WebRequestMethods.Http.Post
            ' UploadFile is not supported through an Http proxy
            ' so we disable the proxy for this request.
            uploadRequest.Proxy = Nothing

            requestStream = uploadRequest.GetRequestStream()
            fileStream = File.Open("c:\temp\MyActions_Partial_Feed_Format.xml", FileMode.Open)

            Dim buffer(1024) As Byte
            Dim bytesRead As Integer
            While True
                bytesRead = fileStream.Read(buffer, 0, buffer.Length)
                If bytesRead = 0 Then
                    Exit While
                End If
                requestStream.Write(buffer, 0, bytesRead)
            End While

            ' The request stream must be closed before getting the response.
            requestStream.Close()

            uploadResponse = uploadRequest.GetResponse()
            Dim responseReader As StreamReader = New StreamReader(uploadRequest.GetResponse.GetResponseStream())
            Dim x As String = responseReader.ReadToEnd()
            responseReader.Close()
            AddText(x)



        Catch ex As UriFormatException
            AddText(ex.Message)
        Catch ex As IOException
            AddText(ex.Message)
        Catch ex As Net.WebException
            AddText(ex.Message)
        Finally
            If uploadResponse IsNot Nothing Then
                uploadResponse.Close()
            End If
            If fileStream IsNot Nothing Then
                fileStream.Close()
            End If
            If requestStream IsNot Nothing Then
                requestStream.Close()
            End If
        End Try

vbscript 让用户按Ctrl-A选择VB .NET中的TextBox中的所有文本<br/>当TextBox的KeyPress事件看到Ctrl-A键代码(1)时,

让用户按Ctrl-A选择VB .NET中的TextBox中的所有文本<br/>当TextBox的KeyPress事件看到Ctrl-A键代码(1)时,它将事件的发送者强制转换为TextBox并调用TextBox的SelectAll方法。然后代码将e.Handled设置为True以指示已处理该字符。这可以防止TextBox发出哔哔声。

Textbox Select All.vbs
If e.KeyChar = Convert.ToChar(1) Then
        DirectCast(sender, TextBox).SelectAll()
        e.Handled = True
    End If

vbscript 使用System.IO的delete方法删除文件

使用System.IO的delete方法删除文件

File Deletion.vbs
Dim FileToDelete As String
FileToDelete = "file to delete"
If System.IO.File.Exists( FileToDelete ) = True Then
System.IO.File.Delete( FileToDelete )
MsgBox("File Deleted")
End If

vbscript 您可以使用此代码加密和解密存储的值。您还可以设置自己的加密密钥,该密钥将存储在字符串中(加密

您可以使用此代码加密和解密存储的值。您还可以设置自己的加密密钥,该密钥将存储在字符串(EncryptionKey)<br/> <br/> http://www.pcreview.co.uk/forums/encrypt-my-settings-setting-t2642486中。 HTML

Encryption_Decryption.vbs
Imports System.Security.Cryptography
Imports System.Text

Module mod_Globals

Public EncryptionKey As String = "justsomewordstobeusedasacryptionkey"

Public Function EncryptString128Bit(ByVal vstrTextToBeEncrypted As
String, ByVal vstrEncryptionKey As String) As String

Dim bytValue() As Byte
Dim bytKey() As Byte
Dim bytEncoded() As Byte
Dim bytIV() As Byte = {121, 241, 10, 1, 132, 74, 11, 39, 255,
91, 45, 78, 14, 211, 22, 62}
Dim intLength As Integer
Dim intRemaining As Integer
Dim objMemoryStream As New MemoryStream
Dim objCryptoStream As CryptoStream
Dim objRijndaelManaged As RijndaelManaged

vstrTextToBeEncrypted =
StripNullCharacters(vstrTextToBeEncrypted)

bytValue =
Encoding.ASCII.GetBytes(vstrTextToBeEncrypted.ToCharArray)

intLength = Len(vstrEncryptionKey)

If intLength >= 32 Then
vstrEncryptionKey = Strings.Left(vstrEncryptionKey, 32)
Else
intLength = Len(vstrEncryptionKey)
intRemaining = 32 - intLength
vstrEncryptionKey = vstrEncryptionKey &
Strings.StrDup(intRemaining, "X")
End If

bytKey = Encoding.ASCII.GetBytes(vstrEncryptionKey.ToCharArray)

objRijndaelManaged = New RijndaelManaged

Try
objCryptoStream = New CryptoStream(objMemoryStream,
objRijndaelManaged.CreateEncryptor(bytKey, bytIV),
CryptoStreamMode.Write)
objCryptoStream.Write(bytValue, 0, bytValue.Length)
objCryptoStream.FlushFinalBlock()
bytEncoded = objMemoryStream.ToArray
objMemoryStream.Close()
objCryptoStream.Close()
Catch

End Try

Return Convert.ToBase64String(bytEncoded)

End Function

Public Function DecryptString128Bit(ByVal vstrStringToBeDecrypted
As String, ByVal vstrDecryptionKey As String) As String

Dim bytDataToBeDecrypted() As Byte
Dim bytTemp() As Byte
Dim bytIV() As Byte = {121, 241, 10, 1, 132, 74, 11, 39, 255,
91, 45, 78, 14, 211, 22, 62}
Dim objRijndaelManaged As New RijndaelManaged
Dim objMemoryStream As MemoryStream
Dim objCryptoStream As CryptoStream
Dim bytDecryptionKey() As Byte
Dim intLength As Integer
Dim intRemaining As Integer
Dim intCtr As Integer
Dim strReturnString As String = String.Empty
Dim achrCharacterArray() As Char
Dim intIndex As Integer

bytDataToBeDecrypted =
Convert.FromBase64String(vstrStringToBeDecrypted)

intLength = Len(vstrDecryptionKey)

If intLength >= 32 Then
vstrDecryptionKey = Strings.Left(vstrDecryptionKey, 32)
Else
intLength = Len(vstrDecryptionKey)
intRemaining = 32 - intLength
vstrDecryptionKey = vstrDecryptionKey &
Strings.StrDup(intRemaining, "X")
End If

bytDecryptionKey =
Encoding.ASCII.GetBytes(vstrDecryptionKey.ToCharArray)

ReDim bytTemp(bytDataToBeDecrypted.Length)

objMemoryStream = New MemoryStream(bytDataToBeDecrypted)

Try

objCryptoStream = New CryptoStream(objMemoryStream,
objRijndaelManaged.CreateDecryptor(bytDecryptionKey, bytIV),
CryptoStreamMode.Read)
objCryptoStream.Read(bytTemp, 0, bytTemp.Length)
objCryptoStream.FlushFinalBlock()
objMemoryStream.Close()
objCryptoStream.Close()

Catch

End Try

Return StripNullCharacters(Encoding.ASCII.GetString(bytTemp))

End Function


Public Function StripNullCharacters(ByVal vstrStringWithNulls As
String) As String

Dim intPosition As Integer
Dim strStringWithOutNulls As String

intPosition = 1
strStringWithOutNulls = vstrStringWithNulls

Do While intPosition > 0
intPosition = InStr(intPosition, vstrStringWithNulls, vbNullChar)

If intPosition > 0 Then
strStringWithOutNulls = Left$(strStringWithOutNulls, intPosition - 1) & _
Right$(strStringWithOutNulls,
Len(strStringWithOutNulls) - intPosition)
End If

If intPosition > strStringWithOutNulls.Length Then
Exit Do
End If
Loop

Return strStringWithOutNulls

End Function


End Module


'Then to call this code do the following:

'Get Password
Dim strPassword as string = DecryptString128Bit(My.Settings.Password, EncryptionKey)

'Save Password
My.Settings.Password = EncryptString128Bit(txt_Password1.Text.Trim, EncryptionKey)