Quantcast
Channel: VBForums - ASP, VB Script
Viewing all 687 articles
Browse latest View live

Can't run excel macro from VBScript (WireChartEvents error)

$
0
0
Hi everyone,

I'm not an expert on VBA and VBScript, and I'm trying to run an Excel Macro from VBScript in a Windows 7 bloomberg computer and some how I'm not managing to do so.

When running the .vbs file it immediately pops out an error msg saying:

"Run-Time error '1004':

It's not possible to run a macro **'WireChartEvents'**. Maybe it is not avaiable in this folder or all other macros are disabled."

(Maybe the msg is a little different because I'm Brazilian and the msg is in portuguese originaly, so I freely translated it, my self)

The problem is that I have no "'WireChartEvents'" macro in the workbook I'm openning, or in any other as a matter fact (as far as I know). The problem is not in the Macro I'm trying to run because I tried to run an empty macro to make sure the problem was not my coding.

Here is my VBScript:

Dim objExcel

Dim objWorkbook

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = False

objExcel.DisplayAlerts = False

set objWorkbook =

objExcel.Workbooks.Open("R:\LuisNicolau\masterSpreadsheetbbgbase.xlsm")

objExcel.Run "'masterSpreadsheetbbgbase.xlsm'!runBBG"

objExcel.Calculate

objExcel.DisplayAlerts = False

WScript.sleep 30000

objWorkbook.Close True

objExcel.Quit

Set objWorkbook = Nothing

Set objExcel = Nothing


Please someone help me with this, I heve tried looking for a solution in glogs but I found nothing, so any help is highly appreciated. Thanks in advance...

append registry key script not working correctly

$
0
0
Good morning

i have a scenario where i need a value of a registry key to be appended with the original value still retained and added to

the value for example is hkcu\software\test with a string value of 100
i need this to be appended to ,200 so the key looks 100,200
the issue is this is overwriting the value altogether which i dont want

i have the following code
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "test"
strValueName = "english"
strValue = "200"
objRegistry.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue

I also need a check for the script to say if ,200 doesnt exist then run the script

can anyone advise please?

Losing a connection when concatenating vbCrLf

$
0
0
Hi,

I am developing a VB script to access a Unix server to run a series of commands and
ultimately execute a script. I am using the OstroSoft Winsock Component to make the connection
and then I am attempting to log in. The script runs fine when a issue SendData without concatenating
vbCrLf. The problem that presents is I am maintaining my connection (state = 7) which is good, but without the
carriage return / line feed I believe that I am just send a long unrecognized string to the server.
When I have the vbCrLf added the connection closes (state =0). I'm hoping that someone may be able to shed some
light on the issue or help me code it correctly. I am running on Windows 7.

ex. Winsock1.SendData dbrown & vbCrLf

Thanks
David

Cannot Use parentheses when calling a sub

$
0
0
Good afternoon
i am just finishing a script but i have the following scenario

1. script needs to check if the string value is present at all in that particular entry, if it is then DO NOTHING.
2. script checks if reg key exists but the value is missing and amends this
3. script checks for reg structure and creates this if missing.

2 and 3 are done

but i need to put a fail safe in to prevent it writing the characters alongside them already if they are present in the key.
when i copy my code for this i get the "cannot use parentheses when calling a sub error" my code is attached below, i have bolded the part causing me issues, i have basically change the IF NOT to IF for the first check


Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
Set WshShell = CreateObject("WScript.Shell")
strKeyPath = "Software\Microsoft\Internet Explorer\International"
strValueName = "AcceptLanguage"
objRegistry.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue


'-----------Registry Key and Value Exist - DO Nothing-----------------------
IfInstr(1, strValue, "en-GB;q=0.5", 1) > 0 then
End


Else

'----------- Registry Key Exists - Modify Key ------------
If NOT Instr(1, strValue, "en-GB;q=0.5", 1) > 0 then
WshShell.Run """" & "C:\AmendLanguage.vbs" & """"
WScript.Echo "Modifying Registry"


Else

'----------- Registry Key does not exist - create key ------------
WshShell.Run """" & "C:\InputLanguage.vbs" & """"
WScript.Echo "Creating Registry Keys"

can anyone advise how to amend my script so i dont see this error?
Thanks

Asp Page Development in a Chromebook or Android Tablet

$
0
0
I have a web site with a 1000+ web pages that have an .aspx extension. The only thing I really use is the include files as far as scripting, so I'm a complete newbie. Anyway, to do my pages, I use Vis Studio Express 2012 for Web on my laptop. Because I am doing nothing sophisticated, I am wondering if there is some way that I can develop in a chromebook or android tablet? And what I like about the Vis Studio Express is that I have

a) some project management

b) I can see what the page looks like with the WYSIWIG toggle.

Is there anything equivalent for smaller devices?

Thx and sorry to be such a newbie.

VBS copy and paste into another excel match destination formatting

$
0
0
I have been searching online for the answer to this without much luck.

1) I have an excel file that has "general" formatting. It has dates etc. etc. When it is formatted manually within the file to "text" the dates are messed up. (E.G. 3/2/2015 may turn into 112321.12)

2) When I copy the excel file into another excel file that has all the columns formatted to "Text" prior and click "match destination formatting" it will give me the contents of the first excel sheet all in "Text" format.

3) The reason I do this is because I wrote another VBS script to copy the contents into a delimited file to bulk insert it into SQL Server. However, when I bulk insert with the file produced by an excel file that isn't all "text", it will break. When I format it as "text" it works perfectly fine.

4) I need a VBS script to copy the contents of an excel document into another excel document that is formatted with text and retain its date values.

Can someone point me in the right direction or best method in doing this?

SendUsing invalid configuration error code 80040220 solution

$
0
0
This is probably is old news but I think it is worth posting. Last night I wanted to send email with attachment using script but I ran into problem. When I send the email I get SendUsing Invalid Configuration error, Literally spent lots of time trying to figure out a solution. So I google and found most of the threads were old. I did not find any solution. Maybe I did not search hard enough. However, I found an old thread with script that might work. I changed some wordings but the script is similar to the original.

Dim objMessage
Set objMessage = CreateObject("CDO.Message")
With objMessage
.Subject = "type Subject information here"
.From = "type your email address here"
.To = "type email address of the recipient here"
.TextBody = "type text content here"
.AddAttachment "Type attachment path here"
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "Localhost"
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Configuration.Fields.Update
.Send
End With

I spent a lot of time trying to find out why I kept getting SendUsing error. I made changes here and there but the error keeps popping up. I finally found why it won't work. "Localhost" is not a valid input. It has to be literally the smtp server name of the default email account.

I went to my outlook account settings. Double clicked the default email address. Copied the smtp server name. Pasted it in place of "Localhost" and the script worked.

Before:

.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "Localhost"


After:

.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "the name of the smtp sever name of the default email account".

Hope this helps.

Luis.

Deleting part of a string value

$
0
0
Good morning,
I have a custom action which edits the string in a value in the registry to en-gb
is there a way i can remove this from the string without it deleting the entire value or the entire key using vbscript please?

i cant find anything so i am assuming i cant do this?

Thanks

[RESOLVED] TextBox Click Event

$
0
0
following code used to work before but suddenly failed. I tried inserting OnClick="Button4_Click" but that gives me a compilation error.

what is going wrong ?

Code:

<asp:Panel runat="server" DefaultButton="Button4">
                            <asp:TextBox ID="TextBox1" runat="server" Width="200" Enabled="False" AutoPostBack="True"></asp:TextBox>
                            <asp:Button ID="Button4" runat="server" style="display:none"></asp:Button>
                            </asp:Panel>

VBScript: how can i use win32 functions on script?

$
0
0
i'm totally new with VBScript. but i can show a message box:

Code:

MsgBox("hello")
but i can't add a message box title :(
but going to the problem: how can i use the Win32\API functions?

VBScript to do an action on all files in a folder

$
0
0
Hi everyone,

I basically have a vbs script to rename all outlook messages stored as .msg files so that they actually are relevant to someone looking for a specific message. The script works well and does what it's meant to do but I would like to be able to drop whole folders onto the script icon and having the script browse through all files in that folder and do the actions instead of having to select all messages to drop them on the script. Can someone help me with that? Thanks!!

Also, the actual procedure requires me to drag and drop my messages from outlook to a folder and then to drag and drop them on the script. Has anyone ever seen a way to integrate a script into the drag and drop function so that it would do his business as I drag the messages out of outlook?

Here's my script code that works well for files that I drop onto it but does nothing with folders :
Code:

On Error Resume Next
 
Dim olkApp, olkMessage, objFSO, objFile, varFile, varNewFileName, filenamecut
Set olkApp = GetObject(,"Outlook.Application")
If TypeName(olkApp) = "Nothing" Then
    Set olkApp = CreateObject("Outlook.Application")
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each varFile In WScript.Arguments
    Set olkMessage = olkApp.CreateItemFromTemplate(varFile)
    varNewFileName = ReplaceIllegalCharacters(olkMessage.ReceivedTime & " - " & Left(olkMessage.SenderName,20) & " - " & olkMessage.Subject) & ".msg"
Set objFile = objFSO.GetFile(varFile)
    objFile.Name = varNewFileName

 Call ModFileDT (objFile.ParentFolder,objFile.Name,olkMessage.ReceivedTime)

Next
Set objFile = Nothing
Set objFSO = Nothing
Set olkMessage = Nothing
Set olkApp = Nothing
WScript.Quit
 
Function ReplaceIllegalCharacters(strSubject)
    Dim strBuffer
    strBuffer = Replace(strSubject, ":", ".")
strBuffer = Replace(strBuffer, ";", " - ")   
strBuffer = Replace(strBuffer, "\", "")
 strBuffer = Replace(strBuffer, "*", "")
strBuffer = Replace(strBuffer, "+", "et")
    strBuffer = Replace(strBuffer, "/", "")
    strBuffer = Replace(strBuffer, "?", "")
    strBuffer = Replace(strBuffer, Chr(34), "'")
    strBuffer = Replace(strBuffer, "|", "")
strBuffer = Replace(strBuffer, "°", " ")
    ReplaceIllegalCharacters = strBuffer
End Function

Sub ModFileDT(strDir,strFileName,DateTime)
    Dim objShell, objFolder, objFile
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.NameSpace(CStr(strDir))
Set objFile = objFolder.Parsename(CStr(strFileName))
    objFile.ModifyDate = CStr(DateTime)

Set objShell = Nothing
Set objFolder = Nothing
Set objFile = Nothing
End Sub

Thanks for the help!

simple script that asks for a password with inputbox/msgbox/net use

$
0
0
I am looking for a simple vbs that asks for a password with inputbox after you run it. (the password check can happen with plain text in the script - i know it is not secure but it is good enough). if the password is correct it should execute a net use command Y: // ..... after that it should give out a msgbox.
If the password does not match it should return a msgbox. (and optionally send an email to X with subject Y) and then close itself.

would be a huuuge help if someone could write these lines I tried several things and couldnt come up with a conclusion.

How to convert feet and inches into inches using classic .asp

$
0
0
Hi,

I have thousands of different sizes that I need to convert from feet and inches into inches using classic .asp.

The sizes are listed in the following format:

[width] x [height]

The width and height are shown with ' marks, which stand for feet and " marks which stand for inches.

For example, take the following and convert it into inches:

2'6" x 8' = width = 30; height = 96
9'6" x 13'6" = widht = 120; height = 162

Sometimes there is no X in the size, indicating that it is round or square in shape. For example:

2'6"

That would have to make both the width and height the same, so:

2'6" = width = 30; height = 30

Sometimes, there is a trailing " at the end, where there should be inches, but there are none listed. For example:

5'0" x 8'" = width = 60; height = 96

I am guessing that I would need to create some sort of custom function with expressions, but just having a hard time figuring it out. Any pointers would be appreciated.

Help adding current year month and date to script target foler

$
0
0
im still learning VB but i am having i have about given up adding the current year month and date to the target folder this robocopy script i am using

for example my target folder name is E:\Preservations\Ronald_McDonald\Hostname i want it to append the year month and date to the folder like E:\Preservations\Ronald_McDonald\Hostname_20160322

below is the script i am using.

Code:

Set objShell = CreateObject("Wscript.Shell") 

objSource = InputBox("Please enter the Path to the source Data: Example:  \\Hostname\c$", _
    "Source Folder")
If objSource = "" Then
    Wscript.Quit
Else
    MsgBox objSource, 0, "Source Path"
End If

objDestination = InputBox("Please enter the Path to Destination Folder: Example:  C:\Target\Data", _
    "Destination Folder")
If objDestination = "" Then
    Wscript.Quit
Else
    MsgBox objDestination, 0, "Target Path"
End If

objlogpath = InputBox("Please enter the Path and name where the log will be placed: Example:  C:\script_path\hostname.txt", _
    "Path and log name")
If objlogpath = "" Then
    Wscript.Quit
Else
    MsgBox objlogpath, 0, "Log Path"
End If

objcmd = "Robocopy"
objSource = """" & objSource & """"
objDestination = """" & objDestination & """"
objswitches = " /B /S /COPY:DATO /DCOPY:T /R:2 /W:5 /V /TEE"
objlogpath = "/log:" & objlogpath

objCommand = objcmd & Chr(32) & objSource & Chr(32) & objDestination & Chr(32) & objswitches & Chr(32) & objlogpath

Wscript.echo objCommand

objShell.Run(objCommand)

transfer SelectedIndex between two WebForms

$
0
0
I have two WebForm pages, each with a DropDownlist named ddl1. I need to send the selected index from the ddl on the first page to the ddl on the second page, followed by an automated selection of the value in the second ddl.
I am able to send the selected index from the ddl on thefirst page using following code :
Code:

Session("Niveau") = DropDownList1.SelectedIndex
On the second page, I am using
Code:

        DropDownList1.SelectedIndex = Session("Niveau")
This is effectively transferring the selected index from page one to page two, but I was expecting the ddl on the second page to act as if a manual selection was performed (i.e. event on SelecxtedIndexChanged). However, this is not the case. Actually, nothing happens.

I tried some things like ‘ddl.SelectedIndexChanged()’, ‘ddl.click()’ and so on but without any luck.

Has anyone some suggestions as how to invoke an autiomated event after index ddl2 has been changed ?

Why doesn't CMD execute within a VBS launched from Scheduler?

$
0
0
This is my VBS file contents :

Code:

dim com1, com2
com1 = "C:\windows\system32\cmd.exe /c D:\wamp\bin\mysql\mysql5.6.17\bin\mysql.exe -h xxx -u xxx -pxxx xxx < " & chr(34) & "D:\create_vox.sql" & chr(34) & chr(34)
com2 = "C:\windows\system32\cmd.exe /c D:\wamp\bin\mysql\mysql5.6.17\bin\mysql.exe -h xxx -u xxx -pxxx xxx < " & chr(34) & "D:\cdr_table.sql" & chr(34) & chr(34)
CreateObject("wscript.shell").Run com1, 10, True
CreateObject("wscript.shell").Run com2, 10, True

I run it on a schedule within Task Scheduler: with SYSTEM account, highest privileges.

I tried when the script runs alone and does what it is suppose to do. But when I run it through the scheduler, then the above second command (com2) doesn't go through.

[EDIT4]

I've tried :

changing around the intWindowStyle , set it to 0, 1 and 10.

and

Code:

Set tempob1 = CreateObject("WScript.Shell")
Set tempob2 = CreateObject("WScript.Shell")
tempob1.Run com1,,True
tempob2.Run com2,,True

Correct format to attach a file to an email using Outlook in VBS

$
0
0
I have a working VBS script that I had tested and was able to send emails with. It was a kind of template that can be modified for various uses. The problem I hit was when i tried to add a file as an attachment it threw some odd errors and I cannot find out why. It acts like I am leaving off a delimiter such as ) but they all seem to be here.
In researching this problem I found another one which may also prevent it from working as needed anyway. The attached file is .nfo file generated by msinfo32.exe, which may not be an allowed file type.
My intent was to come up with a single package I could send to employees in need of help on their systems, I can generate the NFO file showing everything I would need to know about their system within a batch and then call the mailtome.vbs to send the file to my email.
It all works except for that one error killing it in line 12; This is line 11 forward>

Code:

For a = 0 to objArgs.Count - 1
Set oAttachments = oEmailItem.Attachments.Add(objArgs(c:\temp\test.nfo))
subjectStr = subjectStr & Right(objArgs(a),Len(objArgs(a))-(InStrRev(objArgs(a),"\"))) & ", " 'recreates the default Subject e.g. Emailing: file1.doc, file2.xls
Next
If subjectStr = "" then subjectStr = "No Subject "
oEmailItem.Subject = "MyUtilitiez " & Left(subjectStr, (Len(subjectStr)-2))
oEmailItem.BodyFormat = olFormatHTML
oEmailItem.Display
oEmailItem.Send

Search for a sting in text files Merge those text files

$
0
0
Hello,
I am having a little trouble. Here is what I am trying to do.
Search all text files in a folder for a string
If that string is found than merge those text files that were found.
Any help to point me in the right direction would be great.
I am having no problem with the search for string part

Code:

Set colFiles = objFolder.Files
For Each objFile in colFiles
    'Wscript.Echo objFile.Name
    strFile = "\\path to folder\" & objFile.Name
    set objFile = objFSO.getFile(strFile)
    if objFile.size > 0 then
        If InStr(oFSO.OpenTextFile(strFile).ReadAll, strSearchFor) > 0 Then
          filesys.CopyFile "\\path to folder\" & objFile.Name, "\\path to folder\" & "Name_"& strDate &".txt"
        Else
            WScript.Sleep (100)
        END If
    END If
Next

The above code searches for the needed string and copies the file to a new name. But only for one file. I have more than one file with the search string in it and need to merge all files with the search string in them.

Thank you

Using VB Script to open, save, and close a program

$
0
0
I am trying to have VB open Excel, save the workbook (after a macro runs), then close the workbook. The catch is that I have an Adobe Report-Builder Plugin (used to pull Adobe Analytics into the worksheet) that is set to run (via macro) upon the launch of this particular workbook. It wouldnt be a problem except it has its own set of popup-prompts to save the workbook prior to exiting. Thus, when i want the workbook to close i cant use the following code because the Adobe popup/prompt takes focus
Code:

        xlWb.Save
        xlWb.Close SaveChanges=True
        xl.Quit

So I need to send an "enter" key to that active window (to click "yes" to save). So far i have this. Im not sure if the sendkey command is working correctly or whether i need to point that command to the focus/active window.

Code:

Sub RunMacro()
        Set xl          = CreateObject("Excel.application")
        Set xlWb = xl.Workbooks.Open("C:\Users\me\Documents\workbook.xlsm")
        xl.Application.Visible = True
        xl.Application.run "'workbook.xlsm'!RefreshAllReportBuilderRequests"
        WScript.Sleep 60000
        xlWb.Close
        WScript.Sleep 2000
        Set WshShell = WScript.CreateObject("WScript.Shell")
        WshShell.SendKeys "{ENTER}"
        Set xlWb = Nothing
        Set xl          = Nothing
        Set shell  = Nothing
End Sub

How can I get a file list with the same sorting as Explorer?

$
0
0
Hi! I need to make a directory listing with VBS, but I need to have the files sorted just as they are when you open a directory in Windows Explorer.

For instance, I open a folder with images, and they may be sorted by name, date modified/created, type, etc. They may also be reordered with date taken (if they are photos and have that metadata)

So, how can I get a file list with the same sorting as Explorer?

Thanks a lot!
Viewing all 687 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>