|
Dear all,
Hope you can help me out, i am new to VB scripting and i get the question from a customer to help them out with there VB script, They have the script below that is working fine on a windows 7 + Office 2013 computer but now they are migrated to a Windows 10 device with Office 365 and the script is stoped working.
It is a VB script in Excel/Access that can save the selected e-mail in outlook to a *.msg file:
<pre>Sub SlaMailOp()
Dim olApp As Outlook.Application, olNs As Namespace, Item As Object, eFldr As Object
Dim MailItem As Variant
Dim Onderwerp As String
On Error GoTo ErrorHandler
Set olApp = GetObject(, "Outlook.Application")
tmpOpenTextInvoer = "C:\temp\OpenTextInvoer"
If olApp Is Nothing Then
Set olApp = CreateObject("Outlook.Application")
End If
Set olNs = olApp.GetNamespace("MAPI")
Set eFldr = olNs.Application.ActiveExplorer.Selection
For Each MailItem In eFldr
If Dir(tmpOpenTextInvoer, vbDirectory) = "" Then
MkDir tmpOpenTextInvoer
End If
Onderwerp = PasGeldigheidBestandsnaamAan(Left(MailItem.Subject, 120)) & "_" & Format(Now, "YYMMDDHHMMSS")
MailItem.SaveAs tmpOpenTextInvoer & "\" & Onderwerp & ".msg"
Next
Set olApp = Nothing
Set olNs = Nothing
Set eFldr = Nothing
Exit Sub
ErrorHandler:
MsgBox "Er is een fout opgetreden bij het ophalen van de e-mail informatie! Is Outlook wel opgestart?" & vbCr & Err.Description, vbCritical
End Sub
Function PasGeldigheidBestandsnaamAan(Naam As String)
Naam = Replace(Naam, ":", "_")
Naam = Replace(Naam, "\", "_")
Naam = Replace(Naam, "/", "_")
Naam = Replace(Naam, "*", "_")
Naam = Replace(Naam, "?", "_")
Naam = Replace(Naam, "<", "_")
Naam = Replace(Naam, ">", "_")
Naam = Replace(Naam, "|", "_")
Naam = Replace(Naam, """", "_")
Naam = Replace(Naam, " ", "_")
Naam = Replace(Naam, "€", "EUR")
Naam = Replace(Naam, """, "")
Naam = Replace(Naam, "
Naam = Replace(Naam, "’", "")
Naam = Replace(Naam, "Ë", "E")
Naam = Replace(Naam, "ë", "e")
Naam = Replace(Naam, "Ö", "O")
Naam = Replace(Naam, "ö", "o")
Naam = Replace(Naam, "Ü", "U")
Naam = Replace(Naam, "ü", "u")
Naam = Replace(Naam, "@", "_AT_")
Naam = Replace(Naam, "#", "_")
Naam = Replace(Naam, "___", "_")
Naam = Replace(Naam, "__", "_")
PasGeldigheidBestandsnaamAan = Naam
End Function
Function Ampersand(Naam As String)
Ampersand = Replace(Naam, "&", "&")
End Function
|
|
|
|
|
And?
What does it do that it didn't used to, or not do that it did?
Where does it do that?
What have you tried to find out where and why it fails? What happened?
Are there any messages?
What have you tried?
Where are you stuck?
What help do you need?
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. We can't even run your code under the same conditions you do as we have no access to your systems or the sheet it's a part of...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
sorry, users are getting the error:
application-defined or object-defined error
What is should do is save the selected e-mail in outlook to a folder (*.msg)
|
|
|
|
|
At the risk of repeating myself, what have you done to find out where and why?
What has the debugger shown you?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
If i run the debug it give me the error after the step:
MailItem.SaveAs tmpOpenTextInvoer & "\" & Onderwerp & ".msg"
This is the last step where it should save the email in the folder,
For the test is renamed the folder "OpenTextInvoer" and the script did create the folder after i run it for the first time so in my opinion the autorizations are fine.
Please i am sorry if it sounds really amateurish but i am really new with vb scripting and trying really hard to understand it..
If you have any arguments about things that i need to test please feel free to say me so
|
|
|
|
|
So us eteh debugger and put a breakpoint on that line. Then start looking at what the variables contain, and so what you pass to the SaveAs function. Then check that path and make sure it exists and can be written to by the user.
We can't do any of that for you - finding and fixing script bugs is just the same process as you use in application debugging!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
thanks! i understand,
if i breakpoint the SaveAs function and go/point over the "tmpOpenTextInvoer" i see the folder where it needs to be saved so and that is OK.. if i point over the part "Onderwerk" (Onderwerp is Dutch for Subject) i see the subject from the e-mail that i selecteed in outlook. so that part is working fine
i did remove the folder and run the script and the script created the folder like it should be and for the test i put "everyone" on the group with full access but same error is there...
|
|
|
|
|
So you need to look at all the data in MailItem , and check that you can write a file with that name to that folder manually (i.e. not using SaveAs, but using the same filename).
It may be worth setting up an "all users full access" folder and trying to write your file to that under a "nondescript name": "MySafeFolder\AAA.txt" perhaps.
One of the major changes between Win7 and Win10 is a tightening up of security over the file system, and it's possible that the user that the SaveAs is running under (which is conceivably not the same as your user ID) doesn't have the right permissions over the folder.
But this is speculation - this needs carefully thinking about on the actual system(s) it's failing on, and we have no access to that!
Good luck!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I have a Listbox with items. Some reports are limited to 1 item, and others are limited to 24 items.
Say a report limited to 24 items is selected, and the user chooses 200 items. The event seems to fires 17 times, incrementing the selectedItems count 1 a time. So my MessageBox fires 17 times.
I really only need to fire the MessageBox once. Is there a way to wait for the last event in queue to cycle and then I run my code in the event?
[Edit]
From reading even more, seems to be no cure and I should can the message box, and replace it with a huge label in red that states the message.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
modified 24-Oct-19 14:00pm.
|
|
|
|
|
Is there a way to keep the event from firing? No.
Is there a way to "wait for the queued events"? No.
You're making the mistake of showing a message box on every firing of SelectionChanged. Don't do that, though, you can managed a list of items based on the changing of the selection.
You have to give the users some other way to signify they are done selecting items, like clicking a button.
|
|
|
|
|
Thanks for the validation on "NO"
I get it now. Perhaps that is reserved for diagnostics and troubleshooting.
I just made a warning label in red, and attached a timer to it for 15 secs.
I'll get fancier and make a panel with the label and show/center it in the screen.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
How do I create a program that will make the video conferencing and still have chat rooms?
Work under a multi-user network without the Internet.
thanks
|
|
|
|
|
You're not going to get a direct answer to such a broad question.
"How" is going to be understanding the problem and all the sub problems that make it up, such as interacting with cameras, video clients, transferring data over TCP and UDP, writing what amounts to a media server, ... and there's LOTS and LOTS of problems to solve that make up those problems.
Frankly, this is a huge undertaking and if you're even asking this question, you're not ready to tackle it.
|
|
|
|
|
Good afternoon. I have an issue with a stepper motor where I need to control it via an RS232 connection. The motor and control board are very old (circa 1993) and they came with code in Basic language meant to control the motor. I am trying to use that code in the Vintage BASIC interpretor available online, but I'm getting an error code telling me there is an unexpected end of the file. Is there anywhere I can go to debug a simple BASIC program and try and find out where the error is coming from? This, unfortunately, is not something I do (I don't really have any coding experience, at least not since I was very young). The code is pretty short, it's only 90 lines long, so there really isn't all that much to check.
Thanks to anyone who might be able to help.
|
|
|
|
|
Which implementation of Basic was it designed for? There's a few dialects out there, each with subtle differences in syntax. If you post a fragment, someone here might recognize it
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
We used to get unexpected end of file errors in some old MSBasic (MS-DOS days - I really am old!!).
This usually tracked down to a non-visible character embedded in a line of source code which displayed as a space. It was a pain to track down - couldn't use any search because we didn't know what we were searching for.
In the end we spotted the errant lines by using TYPE filename.BAS - these days you would do that in a command window (still can't stop myself calling it a dos box though). Then we just overtyped that line.
|
|
|
|
|
Hello!
What is the code to force Windows to refresh the display settings? I have a VB .NET Forms application that has been steadily updated long enough that it has moved through multiple .NET versions and deployed across Windows XP, Windows 7, and now Windows 10 (we were able to avoid Vista and 8).
Now, on Windows 10 running on an HP, I have a display problem. The problem in the HP, but there is a work around that I would like to trigger from the application.
To fix the problem, after launching the app (from DEV or EXE):
1) Dock / Undock (switching between native and attached displays)
2) Open display settings and change something (resolution, scale, etc.)
3) Perform some other, similar display adjustment that requires the OS to update all of the resolution/scaling constants.
In each case, when change the display or display settings, the problem is resolved, and when I change back, things continue to work fine. It also does not matter if I start on the laptop display or the attached displays. I can duplicate the behavior and fix on multiple HPs running windows 10.
What I need is code to force Windows to refresh the display settings.
Background: The problem is clearly in the OS, likely the display driver. However, HP has been having issues with display drivers ever since the rush to market with the Thunderbolt and they have yet to fix most of those problems. HP blames Microsoft, Microsoft blames HP, nothing gets fixed.
Using app level functions, such as Refresh, and PerformAutoScale do not do the trick. The problem appears to be that windows is reporting different values to the application on container size, and usable size. The app initially draws the controls to the correct container size, but then only repaints a smaller usable size.
Making the window smaller (reducing the container size to below the apparent usable size) and then bigger again, does not make the problem go away - there is a fixed "usable size" that the app will not repaint beyond the borders of, even when the container goes beyond that size. What is interesting about this is that the app will update the data in the controls beyond this "usable size" - it just doesn't properly repaint, instead it adds the new text on top of the old text. It also leaves behind the drawn window edges as the container is sized larger.
Another interesting tidbit is that I can run the app, perform the work around to "fix" the problem, and then close the app. Upon reopening the app, the problem returns, and the work around is again required.
Please help with both a code driven work around, or even better, an OS level fix.
The particulars:
1) VB .NET in Visual Studio 2017 (version 15.9.16)
2) Windows 10 (up to date per Microsoft)
3) HP ZBook Mobile Workstation "Bang & Olufsen" with i7, lots of memory (has no problem with Solid Works 2017)
4) Display drivers for both laptop internal, and Thunderbolt dock external up to date
5) Behavior duplicated on second HP (same config) with Windows 10; same app continues to run just peachy on second HO (same config) running Windows 7.
Todd
|
|
|
|
|
Windows 10 does not "default" the same as previous versions.
In some cases, it will set a "minimum" height or width which any attempt to override, without changing the "minimum", will be defeated.
In other case, a property that was expected to return a number in ALL cases, will now return a NAN except in certain cases, and another property should be used (e.g. "actual" size versus simply some other dimension).
I suggest you "prototype" some "new" forms under Windows 10 and get familiar with the "live property" inspector before concluding it's hardware, drivers, etc.
And upgrade to VS 2019, insuring you understand what it means to select a particular "Windows 10 Build" version.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Not sure I follow most of your thread, but tried your advice of prototyping new forms. Found the behavior extremely inconsistent, but eventually repeated.
Disregard all of my "theory" on what it is doing and focus on the symptoms:
1) When the Form is larger than a certain size (the X and Y dims of this "max size" are not consistent), the controls, specifically a DataGridView in a TableLayoutPanel do not properly repaint as the content, size or position is changed.
2) Changing the values of Minimum Size, Maximum size, Starting size, Starting position, Window State, etc. do not have an effect (other than, of course, restricting the size to small).
3) Altering the OS level display adapter settings (such as Zoom) after running the app makes the problem go away for that session.
4) This only happens on Windows 10 with the HP Z Book. Of note: the HDPI, Zoom, and DPI-Awareness crap all came at the same time with Windows 10 (even though the underlying hardware is literally the same).
On the last point, VS gives me 2 options (starting with or without automatic scaling), neither of which works.
Disable DPI-awareness in Visual Studio - Visual Studio | Microsoft Docs[^]
Thus my original request of how to programatically adjust the display zoom.
|
|
|
|
|
|
You are focussing heavily on code, and how to solve this "problem" in the Windows UI.
You stated yourself that it only happens on a particular model. No amount of code is going to help with a faulty driver.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Maybe a dumb reply by me, but did you set your anchor points?
Like a control on the top left of a form anchors to the top left.
I don't like talking about this subject because it's sort of voodoo here, but I'm pretty sure with VB Winforms, when a form changes size, or a label changes text, it sends a message to the Windows OS message pump just like in Win32, and the message pump queues the screen change or update. I was told to never use "Application.DoEvents()" because it very bad but I suspect it's purpose is to pause your program execution and let the message pump catch up and process it's queue so that the screen can update.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
I'm using DataGridViews docked "full" inside a TableLayoutPanel. Therefore, I haven't touched the the anchor points.
Changing OS level display settings (such as Zoom) makes the problem "go away" for the current session. So, I'd like to be able to change the display zoom programatically until HP and Microsoft come to a solution.
|
|
|
|
|
Todd (10789346) wrote: until HP and Microsoft come to a solution
Don't count on that ever happening.
|
|
|
|
|
I appear to have found a solution, and it does not require invoking OS level setting changes.
Through a lot of trial and experimenting, I found the behavior is specifically related to the DataGridView control. Through some research, an old thread proved to have a workable answer: Invoking DoubleBuffered on the control.
The details are on StackOverFlow: [^]
The code is here:
typeof(DataGridView).InvokeMember(
"DoubleBuffered",
BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty,
null,
myDataGridViewObject,
new object[] { true }); OR
DataGridView1.GetType.InvokeMember("DoubleBuffered", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.SetProperty, Nothing, DataGridView1, New Object() {True})
|
|
|
|
|