unexpected excel crash at saving [closed] - excel

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Anyone could tell me why excel crashes at line
Workbooks(strFichero).Save 'Here
'Cierro libro, guardando
Do Until Workbooks(strFichero).Saved
Workbooks(strFichero).Save
Loop
Workbooks(strFichero).Close

You are not giving it enough time to save. Also you do not need a loop like #BigBen mentioned. Simply use Workbooks(strFichero).Save.
You need to give time after the save command so that excel can save. Add DoEvents before Workbooks(strFichero).Close and it will be ok.
For example
Workbooks(strFichero).Save
DoEvents
Workbooks(strFichero).Close
Alternatively you can also use this one liner
Workbooks(strFichero).Close (True)
'OR
Workbooks(strFichero).Close SaveChanges:=True
You can use the SaveChanges parameter of Workbook.Close method (Excel)
expression.Close (SaveChanges, FileName, RouteWorkbook)

Related

Open a folder from a button in excel [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have a button that I would like to open a folder. The folder directory is saved in cell S47 and looks like (C:\Template\2020-05\Open). My current code opens the file explorer but not to the location of the cell directory.
Sub openfolder()
Dim fPath As String
fPath = Sheet4.Range("S47").Value
Call Shell("explorer.exe " & fPath, vbNormalFocus)
End Sub
I don't know what I am doing wrong with this code but I feel like its a simple solution that I'm just skipping over.
I ran your exact code:
Sub openfolder()
Dim fPath As String
fPath = Sheet4.Range("S47").Value
Call Shell("explorer.exe " & fPath, vbNormalFocus)
End Sub
Using:
and my Desktop opened:
Suggest you re-check the path in S47.Also make sure the data is in Sheet4

Detect Keyboard present in VB6 [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have a legacy VB6 project that can now run on systems without a keybord attached. In that case the program opens the MS on screen keyboard. I need to detect if a keyboard is attached or not. If there is a keyboard attached then skip opening the the on screen keyboard. At the moment it opens the on screen keyboard and the user must then close it. It is Clunky. I cannot migrate this application because it supports some legacy equipment that cannot be accessed by VB.net. Any Ideas please.
Windows Management Instrumentation is one way you could go. The following code looks for keyboards with an OK status:
Private Function hasKeyboard() As Boolean
Dim WMIService As Object
Dim Items As Object
Dim Item As Object
hasKeyboard = False
Set WMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set Items = WMIService.ExecQuery("SELECT * FROM Win32_Keyboard")
For Each Item In Items
If InStr(1, UCase(Item.Status), "OK") > 0 Then
hasKeyboard = True
Exit Function
End If
Next
End Function

Getting a not Definded error when the program tries to close the window? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
Experimenting with Tkinter and Gui creating and cant seem to run two commands off of one button press.
I've already tried moving the second definition out of the first definition to the same error as before. The problem is that it is a separate window to my main window and so is under a different definition meaning. When I've tried the previous threads answers it isn't working for me.
def cheese():
fll = Tk()
#The two commands linked together
def fildes():
filling2()
fll.destroy
fll.title=("Test")
ll = Label(fll, text ="Would you like to choose another topping?").pack()
#The button under this runs fildes()
bb = Button(fll, text ="Yep", command = fildes).pack()
bbb = Button(fll, text ="No", command = fll.destroy).pack()
It should create a window and when the yes button is pressed open a new window while closing the current window.
It opens the new window but fails too delete the current window due to fll not being defined
def fildes():
filling2()
fll.destroy()
this does not work either
Solution:
Always try to pass the arguments to your functions. If I'm seeing this right, Tkinter only calls the standalone filedes() function, without any knowledge about local variables in cheese.
Pass the window you want destroyed to filedes like this:
def fildes(old:Tk):
old.destroy()
filling2()
Then add fll as parameter to the command of your button. (Can be done like this.)
bb = Button(fll, text ="Yep", command = lambda: fildes(fll))
PS:
When I tried to run your code I had to call .pack() like this or else it wouldn't work:
sample = Button()
sample.pack()

Why can't VBA module actions be reversed? i.e., Ctrl+Z'ed [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
For the past several months I've been writing VBA scripts, and have noticed that, if I write a module that acts upon an Excel workbook/sheet, I'm not able to Ctrl+Z these actions. This, from what I've noticed, applies to any and every action that's performed by the module.
A simple example would be:
Sub test()
Cells(1,1) = "Hello World"
End Sub
Why can't module actions be "reversed"? i.e., undone through Ctrl+Z, or, by utilizing the 'undo' arrow.
P.S. I think this behavior might also apply to any module action within any MS application, though, I could easily be wrong.
No they can't be reversed but you can use my method:
You could save your workbook (ActiveWorkbook.Save) at beginning of each macros then if you want to undo:
Const pathToTheFile as String = "C:\Users\VbaProject\"
Sub Undo()
wb = ActiveWorkbook.Name
Workbooks(wb).Close savechanges:=False
Workbooks.Open Filename:=pathToTheFile & wb
End Sub
You can even bind it to a shortcut...

Need to replace line from one file based on another file in Linux bash shell [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have two files , one as a template and other as a input file for next command. I have to update my input file based on the values in template
First file looks like as shown below
TKTSPEC.2.ASSETATTRID=REVISION&
TKTSPEC.2.REFOBJECTID=31&
TKTSPEC.2.TICKETSPECID=410&
TKTSPEC.2.SECTION=&
TKTSPEC.3.ASSETATTRID=NUM&
TKTSPEC.3.REFOBJECTID=31&
TKTSPEC.3.TICKETSPECID=411&
TKTSPEC.3.SECTION=&
TKTSPEC.4.ASSETATTRID=MPNUM&
TKTSPEC.4.REFOBJECTID=31&
TKTSPEC.4.TICKETSPECID=412&
TKTSPEC.4.SECTION=&
My Template file looks like
TKTSPEC.2.ASSETATTRID=REVISION&
TKTSPEC.2.TABLEVALUE=5&
TKTSPEC.3.ASSETATTRID=NUM&
TKTSPEC.3.TABLEVALUE=RDPVS&
TKTSPEC.4.ASSETATTRID=MPNUM&
TKTSPEC.4.TABLEVALUE=NEWPROJECT&
My Desired output is as follows
TKTSPEC.2.ASSETATTRID=REVISION&
TKTSPEC.2.TABLEVALUE=5&
TKTSPEC.2.REFOBJECTID=31&
TKTSPEC.2.TICKETSPECID=410&
TKTSPEC.2.SECTION=&
TKTSPEC.3.ASSETATTRID=NUM&
TKTSPEC.3.TABLEVALUE=RDPVS&
TKTSPEC.3.REFOBJECTID=31&
TKTSPEC.3.TICKETSPECID=411&
TKTSPEC.3.SECTION=&
TKTSPEC.4.ASSETATTRID=MPNUM&
TKTSPEC.4.TABLEVALUE=NEWPROJECT&
TKTSPEC.4.REFOBJECTID=31&
TKTSPEC.4.TICKETSPECID=412&
TKTSPEC.4.SECTION=&
I have to check the ASSETATTRID from my first file and then insert a new line with corresponding value from the second file.Second file has value for every assetattrid.
Can this be acheived using awk or other linux based commands ?
One way:
awk -F. 'NR==FNR{getline x;a[$2$3]=x;next}$2$3 in a{print;print a[$2$3];next}1' templatefile inpfile
this oneliner may work for you:
awk 'NR==FNR{k=$0;getline;a[k]=$0;next}$0 in a{$0=$0"\n"a[$0]}1' templ input

Resources