Copy a picture between Excel 2010 spreadsheets without causing saving errors - image

I have a macro to copy data and a picture from one workbook (A) to another workbook (B). Workbook B is in Excel 2010. The code works fine if workbook A is an earlier version of Excel such as 97-2003. But if workbook A is also in Excel 2010 format, the code seems to work but upon trying to save the file I get an error ("Errors were detected while saving 'C:...'. Microsoft Excel may be able to save the file by removing or repairing some features...").
The key part of the code (after opening workbook A) is:
For Each s In workbookA.Sheets
If s.Pictures.Count > 0 Then
For Each pic In s.Shapes
If Left(pic.Name, 3) = "Pic" Then
pic.Copy
workbookB.Activate
Worksheets("Sheet1").Range("A1").Select
ActiveSheet.Paste
GoTo gotPicture:
End If
Next pic
End If
Next s
gotPicture:
workbookA.Close
The error is resolved by deleting the picture. Or by saving and closing Workbook B prior to closing Workbook A. Neither of those is a great solution. From my research it sounds like this is an error within Excel 2010 where you can't copy pictures between spreadsheets generally rather than a VBA issue. There might be a patch, but corporate policies and the number of users who will need to run the macro make that a bad option for me.
Is there a good way to get around this? Some way to copy a picture between Excel 2010 spreadsheets that doesn't cause this problem? Thanks.

Ran into this same issue. Got around it by keeping my source documents open until my destination workbook was saved (which, as you point out, isn't great). Hotfix patch from Microsoft:
https://support.microsoft.com/en-us/help/2597034/you-cannot-save-a-workbook-that-contains-an-image-that-was-copied-from

Related

Creating a custom Word Add-In/VSTO

I am attempting to create a Word add-in for Office 2010. I have used Visual Basic in the past but moved on to PowerShell for most of my scripting now.
However, when I'm in Visual Studio creating a new Add-In, I have to use Visual Basic (or C++ but i'm a lot more familiar with VB) and i'm running into problems.
The main problem being, I've never done this before and i've never been asked to do this so I've never looked into how it works.
So far, I've created the project and the ribbon icons. I have 2 icons. One is meant to print the name of the current active file into the document (at the end of the document no matter where I'm at IN the document) and the other is meant to print the path to the active document wherever my cursor is inside the document.
So...I don't expect anyone to write my code for me but, if someone could point me in the direction of a quick "How-To" for these items, i'd appreciate it!
Last update. Google-Fu came through. Looks like I have it working as I want it. In case anyone stumbles onto this thread looking for the same thing, here's what I did.
To insert at the end of a document:
Dim docName = Globals.ThisAddIn.Application.ActiveDocument
Globals.ThisAddIn.Application.ActiveDocument.Content.InsertAfter(Text:=vbCrLf & docName.Name)
To insert at the cursor
Dim docName = Globals.ThisAddIn.Application.ActiveDocument
Globals.ThisAddIn.Application.Selection.InsertAfter(Text:=docName.Path)
Thanks for helping me think through this!

Does Angular CLI prevent timestamp update for *.TS files?

After setting up an Angular 2 program using Angular CLI (following the procedure at https://angular.io/guide/quickstart) and using VS Code (https://code.visualstudio.com/) to work with the files I've noticed that the file timestamps for *.TS files do not get updated. Testing on Windows 10, the problem occurs even if I make a change to a TS file with Notepad and do so immediately after reboot. However, if I copy the TS files to another folder, they show updated timestamps.
When opening other folders, there is an instant display of files, but when opening the app folders with the TS files, there is a delay of several seconds, with a message "Working on it..."
The TS files had been associated with a video processing program ("transport stream" file), but I shifted the association to VS Code, but that didn't fix the problem.
I opened a bug report at https://github.com/Microsoft/vscode/issues/25569 but the VS Code folks could not reproduce the problem, suggesting that it is not seen for many VS Code users. That report is now is some sort of limbo in which it is listed as closed but one can still comment.
So I'm wondering whether the Angular CLI environment prevents timestamp update for the TS files.
Any suggestions on how to get the TS files in an Angular 2 project to show the current timestamp?
Addendum: the problem is not just for ts files. It extends to css files as well, as illustrated in this image in which the file system lists 19 April as the file date for styles.css, but the ToolTip for the file gives the more recent (correct) date:
Clearly some part of this environment is overruling one of 2 displays of the file date.
The problem is not the timestamp; it is the column displayed in Windows Explorer. Instead of the usual "Date Modified" column, "Date" was displayed. I don't think problem is caused by Angular CLI or VSCode. It looks like it is created by the video processing program ("transport stream") file type assignment; removing that file association and assigning *.ts to VSCode prevents the problem from occurring. However, this doesn't fix instances in which it occurred already; here is how to fix those:
In Windows Explorer click View on the menu, then "Add Columns". Uncheck "Date" and check "Date Modified". You may want to remove "Length" as well.

Enable Macros in Outlook

I have some experience in coding VBA, some in Excel, but for years now mostly in Access. I have never written code/macros in Outlook till yesterday. I copied some code from this site and pasted it in a .bas file using notepad. I then imported it into Outlook VBA successfully and gave it a test run with lots of breakpoints so I could follow it. After a few tries I got a partial result, which was an Excel file full of email data. I need help with the code, but today I am unable to even run it. I get a message
"Macros are disabled in this project etc..."
which is confusing because I was able to run this yesterday.
Any suggestions?
You need to change your Macro settings in order to run Macros in Outlook.
File-> Options -> Trust Center -> Trust Center Settings... -> Macro Setttings
After that completly close Outlook (it should not even bein the tray) and start it back again. Now you should be able to run your code.

Windows 7: "Excel found unreadable content"

I'm using PHPExcel to generate a very simple .xls file (PHPExcel_IOFactory::createWriter($PHPExcel, 'Excel5')). Whenever that file is opened on Windows 7 using Excel 2010 or 2007, I get the following error:
Excel found unreadable content in 'XXXXXXX.xls'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes.
When I open the same file in Excel 2010 in Windows XP it works fine. If I open the same file in OpenOffice, it works regardless of the OS.
Windows 7 / Excel 2010: Error
Windows 7 / Excel 2007: Error
Windows XP / Excel 2010: Works
Windows XP / Excel 2007: Works
Any / OpenOffice: Works
When I tell PHPExcel to generate an .xlsx file (PHPExcel_IOFactory::createWriter($PHPExcel, 'Excel2007')), it works fine with all the above combinaisons.
I found countless threads on the MS forums, and it seems to affect only Windows 7 files with Excel files generated by third party libraries (not just PHPExcel). But no one has a solution.
I also found the following MS KB article, but I'm not familiar with the underlying Excel specifications: http://support.microsoft.com/kb/2411912
Has anyone else experienced this?
If it is the problem you've highlighted from the MS Support site, then it's locked somewhere in the innards of PHP_OLE, probably in the PHPExcel_Shared_OLE_PPS_File class. I've raised this as Issue 15508 on the PHPExcel site, and will try to run some debugging over the weekend on a Windows 7 box.
No guarantees of a quick fix: but you've given me a pointer on how to try and recreate the problem, and where to look.
For me it was fixed when I used proper UTF-8 encoded strings instead of ISO-8859-1. Maybe PHPExcel can hint about bad encodings?
You have to write with UTF-8 the title, creator, LastModifiedby etc... fields. This was my solution.

Word 2003 template with VBA macros that does not run properly in Word 2011 for MAC

As the title says, I've got a word template with macros that does not run properly in the new Word version from Office 2011 for MAC.
The thing which seems to not work properly is the following code:
Sub Document_New()
myForm.Show
End Sub
The same is with Document_Open()
It doesn't seem to run this code on the Mac version.
Does anyone know why this won't work on the Mac, or if there's another way around to emulate the document_open/document_new function?
EDIT: The document is in the .dot format. And I tried to save it to .doc, then the Document_open() worked just fine, so it seems to not be working in the .dot format.. And Document_New() is not running in .doc since its not a new templatefile based on a document..
EDIT 2: Seems like it was a once only with the Document_open on .doc files. I cant make it work again. So weird! The only event I get working, and this is only when using the .doc file format, is Document_Close() - this works everytime...
EDIT 3: This is just getting weirder. I made a new .doc document with the following code:
Private Sub Document_Open()
MsgBox ("BlaBlaBla")
End Sub
The code only runs if the Visual Basic Editor is open BEFORE I close the word file and try to open it again. If I close the Visual Basic Editor and then the word file, and then open the word file; The code is not run.
??
All VB application events are suppressed if you have the VB-editor active, and the current project is not running. It is an intentional behavior, to prevent unwanted code execution, hence not debuggable.
I have used Workbook_Open() (in Excel), and I can only see it working on newly open Excel Xls (xlsm on 2010), from a non-open VB-editor Excel application.
It will work if you have other doc/xls already open, but not if vb-editor is up.
Have you checked whether Macros are allowed? Do you have generated a certificate and setup your application as a trusted source?
I'm having similar issues. It seems that MS removed support for the Document_New and Document_Open functions in the Word object model for Word 2011. See http://mac2.microsoft.com/vb/1033/Word/html/womscChangesBetweenWord2010and2011.htm

Resources