Showing posts with label Excel. Show all posts
Showing posts with label Excel. Show all posts

Wednesday, July 8, 2020

I'm getting this error - this workbook contains links to one or more external sources that could be unsafe

As far as I know, this message is a Security Warning that Automatic update of links has been disabled.
To suppress the message and to automatically update the links when you open a workbook, follow these steps:   
  1. Click Microsoft Office File, and then click Options.
  2. Click Advanced.
  3. Under General, click to clear the Ask to update automatic links check box.
https://support.microsoft.com/en-us/kb/826921 (It also applies to Excel 2013)

Friday, February 12, 2016

"File in use" not showing up with users accessing Excel files on mapped drive

We have this kind of issue and the rollup and updates solved the issue. 


File in Use


  Tester123.xlsx is locked for editing
  by 'another user'.
 
Open 'Read-Only' or, click 'Notify' to open read-only and receive notification when the document is no longer in use.

Example:

Dealing with this can give anyone a major headache as it's often random and hard to reproduce at will. What makes resolving this particular problem difficult is that there are multiple causes for the problem, and thus multiple solutions. This article attempts to break the file locking problem down categorically so that it's easy to diagnose and fix. However, please understand that while I promise that I'd love to provide you with a fantastic list of everything that could ever fix this issue, I can't. Due to the many different environment configurations, as well as various software and hardware that can be involved, these steps may not work to resolve your issue or resolve your issue with a 100% success rate. These are only some suggestions for some of the most common things to look for and steps to try.

Things to do to resolve the problem
I. Ensure these rollup and updates for Windows are installed
Install the update in the following rollup and then install the three updates referenced in the rollup article (total of four updates).

Note: Before installing these updates you must first install SP1 for Windows 7 or Windows 2008 R2 (http://support.microsoft.com/kb/976932).
Rollup article:
"An enterprise hotfix rollup is available for Windows 7 SP1 and Windows Server 2008 R2 SP1"http://support.microsoft.com/kb/2775511/EN-US
These are the individual links to the 4 updates to install. You do not need the reg keys mentioned in the article as they are for the specific issues listed with the reg keys which is unrelated.

Update for Windows Server 2008 R2 for Itanium-based Systems (KB2775511)
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=2775511
Update for Windows 7 (KB2732673)

Update for Windows 7 for x64-based Systems (KB2728738)

Update for Windows Server 2008 R2 x64 Edition (KB2878378)
 
II. Install the latest Updates for Excel and/or Office
This is where you go to find cumulative updates that are available from the Microsoft Office team to fix reported problems:

III. Turn off the Preview Pane, Details Pane and pop ups that show information about file and desktop items 

This is a problem that has been reported to affect Windows 7 clients only, not Windows XP. This has been found to be an issue for which both Office and Windows have released updates for. However, while much less frequent, we've seen occurrences where this step may still help. If you are fully updated for both Office and Windows, and can find no other reason or resolution to this issue but this does help, this may be your only solution.

In a Windows Explorer window, do the following:

1. Right click on the Start Button.
2. Click 'Open Windows Explorer'.
3. At the top left click Organize > Layout
4. Uncheck Details Pane and Preview Pane.
5. On a Windows menu, click on Tools > Folder Options.  In the box that opens up, click on the View tab.  Scroll down the list to “Show pop-up description for folder and desktop items” and clear the checkbox and then click OK. 

In Excel:
1. Click File > Open
2. Click Organize > Layout

3. Uncheck 'Details Pane' and 'Preview Pane'
If Outlook is involved:
1. Open a new e-mail.
2. In the "Include" group, click Attach File.
3. Click Organize > Layout 
4. Uncheck 'Details Pane' and 'Preview Pane'.

IV. Add the OpLocks registry keys
Add the following two registry keys to the client machines and then reboot the system:
Key: HKEY_CLASSES_ROOT\CLSID\{993BE281-6695-4BA5-8A2A-7AACBFAAB69E}
Name: EnableShareDenyNone 
Type: REG_DWORD 
Value: 1
Key: HKEY_CLASSES_ROOT\CLSID\{993BE281-6695-4BA5-8A2A-7AACBFAAB69E}
Name: NoOpLock
Type: REG_DWORD 
Value: 1
Note: Both of the above keys must be added for this solution to work.

V. Install operating system updates
1. For Windows 7, Windows 7 Sp1, Windows Server 2008 R2 or Windows Server 2008 R2 SP1 -
"ERROR_SHARING_VIOLATION" error message in Windows XP or in Windows Server 2003 when you try to open a file on an SMB share on a server that is running Windows 7 or Windows Server 2008 R2"
http://support.microsoft.com/kb/2625434
2. For Windows 7, Windows Server 2008 R2
"Temporary files do not synchronize correctly to a non-DFS share on a server from a client computer that is running Windows 7 or Windows Server 2008 R2"
http://support.microsoft.com/kb/2434932
3. For Windows 7, Windows 7 Sp1, Windows Server 2008 R2 or Windows Server 2008 R2 SP1 -
"You cannot access a shared file by using the SMB Version 2 protocol because of a race condition in Windows Server 2008 R2 or in Windows 7"
http://support.microsoft.com/kb/2618190
4. Windows Vista, Windows Server 2008 -
"You share some files on a computer that is running Windows Server 2008 or Windows Vista. Some users try to access these shared files. In this scenario, the computer may restart unexpectedly. Additionally, you receive a Stop error that resembles the following: STOP 0x0000004E (0x0000009A,parameter2, parameter3, parameter4 )PFN_LIST_CORRUPT"
http://support.microsoft.com/default.aspx?scid=kb;EN-US;2447725
5. Windows Server 2003 -
"You have a shared file on a computer that is running Windows Server 2003, Two applications access this shared file concurrently. One application has write access to the file, and the other application has read-only access to the file.After both applications run for some time, such as several hours, the application that has write access cannot write data to the shared file, and this application receives the "Delayed Write Failed" error message. This problem causes data loss or data corruption in the shared file."
http://support.microsoft.com/kb/971295

VI. Use MSConfig to stop third party programs and services, including antivirus software
1. Go to START, and from the RUN line, type MSCONFIG and hit ENTER.
2. The System Configuration Utility will launch. On the General tab, click the Selective Startup option. Then uncheck the boxes labeled "Load Startup Items" and "Load System Services".
3. Click on the Services tab. Find the column header at the top labeled "Service" and left click that column header to sort these services in alphabetical order. Scroll down in the list and find a service called "Windows Installer" and click it so that it has a check in the square box.
4. Click Apply and when the changes are made, the OK button will read "Close". Click this button and you will asked to reboot the machine.
5. After the machine has restarted, click OK when the System Configuration Utility information dialog appears. If the System Configuration Utility itself appears, click the red X at the top right corner of the dialog box. If you are prompted to restart the machine, click the button labeled "Exit Without Restart".

This should get the machine into a state where third party and non essential programs are not started when the computer boots. This includes anti-virus software. Try accessing shared files with these programs shut off.
To get the machine back to Normal mode, open MSConfig again as in Step 1 and on the General tab click the
“Normal” startup option. Click Apply, the Close and reboot the machine.
In cases where the wrong user name is displayed in the file lock dialog
Sometimes where it says 'another user' it has the name of someone that didn't open the file or it has no name at all. Just a big ' ' where a name ought to be. Fear not, there is a fix for this problem. The flavor depends on whether you have Excel 2010 or Excel 2007. The below KB Articles contain hotfixes that address several issues, not just the file locked issue. But in the dialog of the article you will see this as one of the problem descriptions:

Assume that you have an .xls file that is protected by Information Rights Management (IRM) on a network share. When you open the file in Excel 2007, a File In Use dialog box appears. However, the dialog box does not display the correct name of the user who locked the file. Therefore, you cannot edit the file.

Understand that these fixes don't make the File in Use dialog go away, they just correct the problem of showing bogus user name information on the dialog itself.

Excel 2007 - http://support.microsoft.com/kb/2598133

Excel 2010 - http://support.microsoft.com/kb/2598143

Additionally, we have seen this issue when the owner file is not deleted from the directory upon closing the file. The file looks like ~file name.xlsx and contains the user information for who had the file open. . This can happen if something interrupts the process and breaks Excels connection with the file.
An example of this would be if a user had the file open from a server and the server was then rebooted. This causes the connection between the Excel application and the owner file to be broken. When the user then closes the file, Excel does not see the need to remove the owner file from the directory, and this results in the orphaned file. When another user later tries to open the same file from that same directory with the orphaned (~filename.xlsx) file, Excel refers to the existing owner file for the information to present to the user in the file locked dialog, resulting in the incorrect user information being presented. To resolve this issue, you need only to delete the orphaned ~filename.xlsx file from the directory.

Considerations for NetApps storage devices

Note: If the issue is only occurring when using a NetApp or other third party storage, we would recommend engaging the Support Team for the third party technology for additional troubleshooting and assistance.

We have seen cases involving the file locking issue when moving files to a NetApps storage device. First and foremost - update your NetApps device to the latest version. The file locking problems can be fixed just by updating the NetApps device to the latest version. If that fails or if you have the latest version, there are a couple of other things to try. This information was documented at http://netappsky.com/netapp-storage-management/cifs-performance-is-slow-after-investigating-performance-issues-cifs-considerations/ but has since been taken down.

I. Enable oplocks
Make sure that cifs.oplocks.enable is on. Oplocks (opportunistic locks) enable a CIFS client in certain file-sharing scenarios to perform client-side caching of read-ahead, write-behind, and lock information. A client can then read from or write to a file without regularly reminding the server that it needs access to the file in question. This improves performance by reducing network traffic. CIFS oplocks on the filer are on.  By default: You might turn CIFS oplocks off under the following circumstances otherwise, you can leave CIFS oplocks on. 

1. You are using a database application whose documentation recommends that oplocks be turned off.
2. The CIFS clients are on an unreliable network.
3. You are handling critical data and you cannot afford even the slightest data loss.

sasfiler*> options cifs.oplocks.enable on

Make sure that this option is set before the clients connect to the filer.   If they are already connected, do a cifs terminate and cifs restart on the filer.

sasfiler*> options cifs.neg_buf_size 33028
II. Set cifs.oplocks_opendelta
Change the cifs.oplocks_opendelta setting. Under certain workloads setting cifs.oplocks_opendelta to 0 can improve CIFS throughput performance by 3% to 5%. Again, if setting this value to 0 results in client disconnects, reset it to 8 (the default value).  Changing the delay time for sending oplock breaks.  If a client that owns a file oplock sends a file open request, it is temporarily vulnerable to a “race condition” that can occur if the storage system requests an oplock break. To prevent this condition, the storage system delays sending an oplock break according to the delay time value (in milliseconds) specified by the cifs.oplocks.opendelta option.   By default, the default delay time is 0 milliseconds. If your storage system must support some older Microsoft Windows clients, including Microsoft you can set the delay time to another value, such as 8. This means that after the storage system receives or responds to a request to open a file, the storage system will make sure that 8 milliseconds have elapsed before sending an oplock break to that client.   options cifs.oplocks.opendelta time Here, time is the delay in milliseconds.  Setting the cifs.oplocks.opendelta option postpones the sending of oplock break requests to clients that have just opened files. You must consult technical support if you are considering setting this value higher than 35.
sasfiler*> options cifs.oplocks_opendelta 0

sasfiler*> options cifs.oplocks_opendelta 8
For example, try adjusting cifs.oplocks_opendelta to a value of 66 (milliseconds)

You might also want to increase the delay time for sending oplock breaks if you see syslog messages similar to the following:
Mon Jan 21 15:18:38 PST [CIFSAdmin:warning]: oplock break timed out to station JOHN-PC for file \\FILER\share\subdir\file.txt
Considerations for Shared Workbooks
The primary feature of a shared workbook is to allow multiple users to open and edit the files simultaneously. However, if you have chosen to share your workbooks using the 'Share Workbook' feature in the Review ribbon, you may still experience this type of behavior in particular scenarios due to the way in which Excel opens and saves files.
Examples of scenarios that users may experience a similar message using a [Shared] Excel file simultaneously:
Scenario 1:  User 1 opens the [shared] file. User 2 also opens the [shared] file at the same time as User 1.
       Result:  A "file is locked" type of message will be provided.
       Workaround:  An option to "Notify" the user when the file is no longer locked is presented. Choose this option and when the lock is released, the user will be able to then choose to open the file in edit mode. 

Scenario 2:  User 1 saves the [shared] file. User 2 also saves the [shared] file at the same time as User 1.
       Result:  A "file is locked" or "file is locked, try again later" type of message will be provided.
       Workaround:  Wait a short period of time to allow the lock to release and try saving the file again.

Flowchart
The following is a flowchart put together by Kevin Sickler on the Microsoft Excel Support team. It gives direction to this complex issue. Click the picture below to see a larger view:



Friday, April 17, 2015

Excel: Windows can not find.... Make sure you typed the name correctly, and then try again.

I have tried these and it works:
  • Button Office(top left)
  • Excel Options(bottom)
  • Advanced(left)
  • (right) Search: General
  • Remove the check mark from "Ignore other applications that use Dynamic Data Exchange(DDE)".
If not working, see:

http://support.microsoft.com/kb/919196/en-us

Monday, February 2, 2015

Oracle SmartView Installation


Installation Steps
You must have Administrator access on the computer to install. All office products including Outlook should be closed.
1. Download SmartView.exe from http://www.oracle.com/technetwork/middleware/smart-view-for-office/overview/index.html and save to desktop.
2. Right-click on the SmartView.exe executable copied to the desktop and Run as administrator.


3. Follow instructions on the install:

        a. Click “Next”
       

          b. Click “Install”


c. Wait for the program to install


d. Click “Finish”


4. After the Install of SmartView is complete, Open Microsoft Excel
5. Select Smart View from the menu

6. Select Open and click SmartView Panel, the Smart View Ribbon is displayed
7. In the Smart View Ribbon, select Options. Within the Options window select Advanced


8. In the Shared Connections URL section, input the following URL

9. In the Display section, check the “Disable Smart View in Outlook” then click OK
Smart View Ribbon


Smart View Timeout Settings (Run as administrator)
The Windows registry on the client’s PC also needs to be updated to include three new key entries in the “Internet Settings” section:

1. ReceiveTimeout
2. KeepAliveTimeout
3. ServerInfoTimeout

The following steps need to be performed:
1. Launch Windows Registry Editor (Regedit) as an administrator. In Windows 7, navigate to C:\Windows and right click on regedit.exe
The “Registry Editor” window is displayed:


2. Navigate (drill-down) to the following path on the client’s PC.
Path: [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
Page 6 of 10
 To drill-down into the registry, perform the following:
o Double-Click on HKEY_CURRENT_USER
o Double-Click on Software
o Double-Click on Microsoft
o Double-Click on Windows
o Double-Click on CurrentVersion
o Double-Click on Internet Settings

3. Add the new registry keys.


 Right-Click on “Internet Settings”.
 Select “New” from the pop-up list.
 Select “DWORD (32-bit) Value” from the pop-up list.
 Text box is displayed and “New Value #1” is highlighted:
o Type in “ReceiveTimeout” and press the Enter key.
 Right-Click on the “ReceiveTimeout” registry key.


o Click on “Modify…” from the pop-up list.


 Enter the following info:
o Value data: 00dbba00
 Click on the “OK” button

4. Repeat step 3 for the following two registry keys:

   Registry Key                   Key Type                            Key Value
1. KeepAliveTimeout    DWORD (32-bit) Value         00dbba00
2. ServerInfoTimeout    DWORD (32-bit) Value         00dbba00

The Registry Editor for the “Internet Settings” should now have the new keys and values assigned to them.


 Verify the above highlighted keys exist and have the assigned values as listed above and below in the table.
    Name                                           Type                        Data
1. KeepAliveTimeout           REG_DWORD     0x00dbba00 (14400000)
2. ReceiveTimeout               REG_DWORD      0x00dbba00 (14400000)
3. ServerInfoTimeout           REG_DWORD      0x00dbba00 (14400000)

After making these adjustments, the client should be able to query almost a million cells using Office 2007/2010 (via Internet Explorer 8 HTTP) without a timeout error.

Internet Options Setting in IE7 or IE8
1. Under Tools/Internet Options/Security select “Custom Level”


2. Click “Enable” for all options under Downloads


3. Click “Enable” under “Allow script-initiated windows without size or position constraints” and
click OK


Sunday, February 1, 2015

Hyperion SmartView tab disappears from Excel

Smartview 11, user complains that Hyperion tab in Excel 2003, 2007, 2010, 2013 has disappeared.
  1. Check that the plug is not disabled in Excel.
  2. Close Excel
  3. Create %APPDATA%\Microsoft\Addins
  4. Copy HsAddIn.dll, HsSpread.dll, HyperionSmartTag.dll and HsTbar.xla from c:\Hyperion\SmartView\bin over to %APPDATA%\Microsoft\Addins
  5. Unregister each of the existing DLLs by running
    regsvr32 /u c:\Hyperion\Smartview\bin\NAMEOF.dll
    Run this command once for each of the copied DLLs.
  6. Register each of the copied DLLs by running
    regsvr32 %APPDATA%\Microsoft\Addins\NAMEOF.dll
  7. Re-Open Excel and the Hyperion tab should be visible again

Sunday, March 9, 2014

How to insert a picture into the header or the footer in Excel Print Print Email Email


 How to insert a picture in the header or the footer

To insert a picture into the header or the footer of a worksheet, use one of the following methods.

Method 1: Microsoft Office Excel 2007

  1. Start Excel.
  2. Click the Insert tab.
  3. Click Header & Footer in the Text group.
  4. Click the area inside the header or footer where you want to add the picture.
  5. On the Design tab, click Picture under Header & Footer Tools in the Header & Footer Elements group.
  6. Locate and select the picture that you want to insert, and then click Insert. The text &[Picture] will appear where the picture is positioned.

Method 2: Microsoft Office Excel 2003

  1. Start Excel.
  2. On the View menu, click Head and Footer.
  3. Click Custom Header or Custom Footer (depending on where you want to add the picture).
  4. Click anywhere in the Left section box, the Center section box, or the Right section box.
  5. On the row of buttons in the Header or the Footer dialog boxes, click Insert Picture, and then find the graphic that you want to insert.
  6. Double-click the graphic.
  7. Click OK two times.

How to improve the appearance of a worksheet that contains a picture in the header or in the footer

Use one of the following methods to improve the appearance of the worksheet and to make sure that all the data is displayed:
  • Increase the header margin by dragging the margin indicators that appear on the screen.
  • Change the size of the picture.

How to change the size of the picture

To change the size of the picture, use one of the following methods:
Method 1: Microsoft Office Excel 2007
  1. Click the header or the footer that contains the picture that you want to adjust.
  2. Click any location inside the &[Picture] text.
  3. Click the Design tab under Header & Footer Tools.
  4. Click Format Picture in the Header & Footer Elements group.
  5. Type .5 in the Height box.

    Note Because both the Lock aspect ratio and the Relative to original picture size check boxes are selected, the width changes in proportion to the change that you make in the Height box.
  6. Click OK to close the Format Picture dialog box.
Method 2: Microsoft Office Excel 2003
  1. On the View menu, click Head and Footer.
  2. Click Custom Header or Custom Footer.
  3. Click any where in the &[Picture] text.
  4. Click the Format Picture button.
  5. Click to clear the Height check box, and then type .5 in the Height box.

    Because both the Lock aspect ratio and the Relative to original picture size check boxes are selected, the width changes in proportion to the change that you make in the Height box.
  6. Click OK three times.
Note If you decide to move the picture to another section of the header or the footer after you have positioned and formatted it, you can copy and paste the code &[Picture], but you must select the picture again and reformat it if you do so.

Wednesday, January 22, 2014

Fixing Issue Where Users Unable to Set Default Printer

A KB to fix the issue whereby end users are unable to set their default printer and furthermore there is currently no default printer set.
This occurs when the end user loses access to a particular key in the Windows Registry.
1.

Open Regedit as an admin user

a) Click the round Start buttuon
b) Type Regedit into the Search box and open it when it appears
2.

Connect to the remote computer

a) Click File > Connect Network Registry
b) Enter the computer name and click OK
3.

Navigate to the correct Registry key

Expand the remote computer's Registry at the following node:
HKU > {User's SID} > Software > Microsoft > Windows NT > Current Version > Windows
Note: You can determine the correct SID using PsGetSid from Sysinternals.
4.

Reset the permissions on the Windows key

a) Right-click on the Windows key
b) Click Permissions
c) Click Advanced
d) Tick Include inheritable permissions from this object's parent
e) Press OK

Wednesday, February 29, 2012

To unlock Excel worksheet or workbook protection


You can download the workbook allinternalpasswords.xls if you don't want to cut and paste the macro below.

Option 1. Open allinternalpasswords.xls. And then open the excel protected file. Press ALT + F11 to open VBA, run the macro. then save.

Option 2. Open protected file, press ALT + F11 to open VBA. Click Insert >> Module then copy and paste the script below  and then run the macro



Option Explicit


Public Sub AllInternalPasswords()
    ' Breaks worksheet and workbook structure passwords. Bob McCormick
    '  probably originator of base code algorithm modified for coverage
    '  of workbook structure / windows passwords and for multiple passwords
    '
    ' Norman Harker and JE McGimpsey 27-Dec-2002 (Version 1.1)
    ' Modified 2003-Apr-04 by JEM: All msgs to constants, and
    '   eliminate one Exit Sub (Version 1.1.1)
    ' Reveals hashed passwords NOT original passwords
    Const DBLSPACE As String = vbNewLine & vbNewLine
    Const AUTHORS As String = DBLSPACE & vbNewLine & _
            "Adapted from Bob McCormick base code by " & _
            "Norman Harker and JE McGimpsey"
    Const HEADER As String = "AllInternalPasswords User Message"
    Const VERSION As String = DBLSPACE & "Version 1.1.1 2003-Apr-04"
    Const REPBACK As String = DBLSPACE & "Please report failure " & _
            "to the microsoft.public.excel.programming newsgroup."
    Const ALLCLEAR As String = DBLSPACE & "The workbook should " & _
            "now be free of all password protection, so make sure you:" & _
            DBLSPACE & "SAVE IT NOW!" & DBLSPACE & "and also" & _
            DBLSPACE & "BACKUP!, BACKUP!!, BACKUP!!!" & _
            DBLSPACE & "Also, remember that the password was " & _
            "put there for a reason. Don't stuff up crucial formulas " & _
            "or data." & DBLSPACE & "Access and use of some data " & _
            "may be an offense. If in doubt, don't."
    Const MSGNOPWORDS1 As String = "There were no passwords on " & _
            "sheets, or workbook structure or windows." & AUTHORS & VERSION
    Const MSGNOPWORDS2 As String = "There was no protection to " & _
            "workbook structure or windows." & DBLSPACE & _
            "Proceeding to unprotect sheets." & AUTHORS & VERSION
    Const MSGTAKETIME As String = "After pressing OK button this " & _
            "will take some time." & DBLSPACE & "Amount of time " & _
            "depends on how many different passwords, the " & _
            "passwords, and your computer's specification." & DBLSPACE & _
            "Just be patient! Make me a coffee!" & AUTHORS & VERSION
    Const MSGPWORDFOUND1 As String = "You had a Worksheet " & _
            "Structure or Windows Password set." & DBLSPACE & _
            "The password found was: " & DBLSPACE & "$$" & DBLSPACE & _
            "Note it down for potential future use in other workbooks by " & _
            "the same person who set this password." & DBLSPACE & _
            "Now to check and clear other passwords." & AUTHORS & VERSION
    Const MSGPWORDFOUND2 As String = "You had a Worksheet " & _
            "password set." & DBLSPACE & "The password found was: " & _
            DBLSPACE & "$$" & DBLSPACE & "Note it down for potential " & _
            "future use in other workbooks by same person who " & _
            "set this password." & DBLSPACE & "Now to check and clear " & _
            "other passwords." & AUTHORS & VERSION
    Const MSGONLYONE As String = "Only structure / windows " & _
             "protected with the password that was just found." & _
             ALLCLEAR & AUTHORS & VERSION & REPBACK
    Dim w1 As Worksheet, w2 As Worksheet
    Dim i As Integer, j As Integer, k As Integer, l As Integer
    Dim m As Integer, n As Integer, i1 As Integer, i2 As Integer
    Dim i3 As Integer, i4 As Integer, i5 As Integer, i6 As Integer
    Dim PWord1 As String
    Dim ShTag As Boolean, WinTag As Boolean
    
    Application.ScreenUpdating = False
    With ActiveWorkbook
        WinTag = .ProtectStructure Or .ProtectWindows
    End With
    ShTag = False
    For Each w1 In Worksheets
            ShTag = ShTag Or w1.ProtectContents
    Next w1
    If Not ShTag And Not WinTag Then
        MsgBox MSGNOPWORDS1, vbInformation, HEADER
        Exit Sub
    End If
    MsgBox MSGTAKETIME, vbInformation, HEADER
    If Not WinTag Then
        MsgBox MSGNOPWORDS2, vbInformation, HEADER
    Else
      On Error Resume Next
      Do      'dummy do loop
        For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
        For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
        For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
        For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
        With ActiveWorkbook
          .Unprotect Chr(i) & Chr(j) & Chr(k) & _
             Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _
             Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
          If .ProtectStructure = False And _
          .ProtectWindows = False Then
              PWord1 = Chr(i) & Chr(j) & Chr(k) & Chr(l) & _
                Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
                Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
              MsgBox Application.Substitute(MSGPWORDFOUND1, _
                    "$$", PWord1), vbInformation, HEADER
              Exit Do  'Bypass all for...nexts
          End If
        End With
        Next: Next: Next: Next: Next: Next
        Next: Next: Next: Next: Next: Next
      Loop Until True
      On Error GoTo 0
    End If
    If WinTag And Not ShTag Then
      MsgBox MSGONLYONE, vbInformation, HEADER
      Exit Sub
    End If
    On Error Resume Next
    For Each w1 In Worksheets
      'Attempt clearance with PWord1
      w1.Unprotect PWord1
    Next w1
    On Error GoTo 0
    ShTag = False
    For Each w1 In Worksheets
      'Checks for all clear ShTag triggered to 1 if not.
      ShTag = ShTag Or w1.ProtectContents
    Next w1
    If ShTag Then
        For Each w1 In Worksheets
          With w1
            If .ProtectContents Then
              On Error Resume Next
              Do      'Dummy do loop
                For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
                For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
                For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
                For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
                .Unprotect Chr(i) & Chr(j) & Chr(k) & _
                  Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
                  Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
                If Not .ProtectContents Then
                  PWord1 = Chr(i) & Chr(j) & Chr(k) & Chr(l) & _
                    Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
                    Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
                  MsgBox Application.Substitute(MSGPWORDFOUND2, _
                        "$$", PWord1), vbInformation, HEADER
                  'leverage finding Pword by trying on other sheets
                  For Each w2 In Worksheets
                    w2.Unprotect PWord1
                  Next w2
                  Exit Do  'Bypass all for...nexts
                End If
                Next: Next: Next: Next: Next: Next
                Next: Next: Next: Next: Next: Next
              Loop Until True
              On Error GoTo 0
            End If
          End With
        Next w1
    End If
    MsgBox ALLCLEAR & AUTHORS & VERSION & REPBACK, vbInformation, HEADER
End Sub







Automatic Save A Backup Copy of A Workbook in Excel 2007


If the Excel file always save a backup file:
1.       Click FILE à Save As à Tools (drop down) à General Options




2.       Unchecked  “Always create backup”. Click OK

Thursday, March 10, 2011

Sum/Count Cells By Fill Or Background Color in Excel


First open the Workbook in which you wish to count or sum cells by a fill color. Now go into the Visual Basic Editor via Tools>Macro>Visual Basic Editor (Alt+F11)and then, from within the Visual Basic Editor go  to Insert>Module to insert a standard module. Now, in this module, enter in the code as shown below;
Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)

 Dim rCell As Range

 Dim lCol As Long

 Dim vResult



''''''''''''''''''''''''''''''''''''''

'Written by Ozgrid Business Applications

'www.ozgrid.com



'Sums or counts cells based on a specified fill color.

'''''''''''''''''''''''''''''''''''''''

  

 lCol = rColor.Interior.ColorIndex



 If SUM = True Then

  For Each rCell In rRange

   If rCell.Interior.ColorIndex = lCol Then

    vResult = WorksheetFunction.SUM(rCell,vResult)

   End If

  Next rCell

 Else

  For Each rCell In rRange

   If rCell.Interior.ColorIndex = lCol Then

    vResult = 1 + vResult

   End If

  Next rCell

 End If



   ColorFunction = vResult

End Function

You can now use the custom function (ColorFunction) like;
=ColorFunction($C$1,$A$1:$A$12,TRUE) to SUM the values in range of cells $A$1:$A$12 that have the same fill color as cell $C$1. The reason it will SUM in this example is because we have used TRUE as the last argument for the custom function.
To COUNT these cells that have the same fill color as cell $C$1 you could use:
=ColorFunction($C$1,$A$1:$A$12,FALSE) or =ColorFunction($C$1,$A$1:$A$12) by omitting the last argument our function will automatically default to using FALSE.
Be aware that the changing of a cells fill color will not cause the Custom Function to recalculate, even if you press F9 (Recalculates the whole Workbook). You will need to either, select the cell and re-enter the formula, or go to Edit>Replace and replace = with =, or use Ctrl+Alt+F9

Saturday, February 12, 2011

How to convert a numeric value into English words in Excel

This article contains sample Microsoft Visual Basic for Applications functions that you can use to convert a numeric value in a Microsoft Excel worksheet cell into its equivalent in English words.



How to create the sample function Called SpellNumber

  1. Start Microsoft Excel.
  2. Press ALT+F11 to start the Visual Basic Editor.
  3. On the Insert menu, click Module.
  4. Type the following code into the module sheet.
Code:

Option Explicit
'Main Function
Function SpellNumber(ByVal MyNumber)
    Dim Dollars, Cents, Temp
    Dim DecimalPlace, Count
    ReDim Place(9) As String
    Place(2) = " Thousand "
    Place(3) = " Million "
    Place(4) = " Billion "
    Place(5) = " Trillion "
    ' String representation of amount.
    MyNumber = Trim(Str(MyNumber))
    ' Position of decimal place 0 if none.
    DecimalPlace = InStr(MyNumber, ".")
    ' Convert cents and set MyNumber to dollar amount.
    If DecimalPlace > 0 Then
        Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
                  "00", 2))
        MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
    End If
    Count = 1
    Do While MyNumber <> ""
        Temp = GetHundreds(Right(MyNumber, 3))
        If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
        If Len(MyNumber) > 3 Then
            MyNumber = Left(MyNumber, Len(MyNumber) - 3)
        Else
            MyNumber = ""
        End If
        Count = Count + 1
    Loop
    Select Case Dollars
        Case ""
            Dollars = "No Dollars"
        Case "One"
            Dollars = "One Dollar"
         Case Else
            Dollars = Dollars & " Dollars"
    End Select
    Select Case Cents
        Case ""
            Cents = " and No Cents"
        Case "One"
            Cents = " and One Cent"
              Case Else
            Cents = " and " & Cents & " Cents"
    End Select
    SpellNumber = Dollars & Cents
End Function
      
' Converts a number from 100-999 into text 
Function GetHundreds(ByVal MyNumber)
    Dim Result As String
    If Val(MyNumber) = 0 Then Exit Function
    MyNumber = Right("000" & MyNumber, 3)
    ' Convert the hundreds place.
    If Mid(MyNumber, 1, 1) <> "0" Then
        Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
    End If
    ' Convert the tens and ones place.
    If Mid(MyNumber, 2, 1) <> "0" Then
        Result = Result & GetTens(Mid(MyNumber, 2))
    Else
        Result = Result & GetDigit(Mid(MyNumber, 3))
    End If
    GetHundreds = Result
End Function
      
' Converts a number from 10 to 99 into text. 
Function GetTens(TensText)
    Dim Result As String
    Result = ""           ' Null out the temporary function value.
    If Val(Left(TensText, 1)) = 1 Then   ' If value between 10-19...
        Select Case Val(TensText)
            Case 10: Result = "Ten"
            Case 11: Result = "Eleven"
            Case 12: Result = "Twelve"
            Case 13: Result = "Thirteen"
            Case 14: Result = "Fourteen"
            Case 15: Result = "Fifteen"
            Case 16: Result = "Sixteen"
            Case 17: Result = "Seventeen"
            Case 18: Result = "Eighteen"
            Case 19: Result = "Nineteen"
            Case Else
        End Select
    Else                                 ' If value between 20-99...
        Select Case Val(Left(TensText, 1))
            Case 2: Result = "Twenty "
            Case 3: Result = "Thirty "
            Case 4: Result = "Forty "
            Case 5: Result = "Fifty "
            Case 6: Result = "Sixty "
            Case 7: Result = "Seventy "
            Case 8: Result = "Eighty "
            Case 9: Result = "Ninety "
            Case Else
        End Select
        Result = Result & GetDigit _
            (Right(TensText, 1))  ' Retrieve ones place.
    End If
    GetTens = Result
End Function
     
' Converts a number from 1 to 9 into text. 
Function GetDigit(Digit)
    Select Case Val(Digit)
        Case 1: GetDigit = "One"
        Case 2: GetDigit = "Two"
        Case 3: GetDigit = "Three"
        Case 4: GetDigit = "Four"
        Case 5: GetDigit = "Five"
        Case 6: GetDigit = "Six"
        Case 7: GetDigit = "Seven"
        Case 8: GetDigit = "Eight"
        Case 9: GetDigit = "Nine"
        Case Else: GetDigit = ""
    End Select
End Function

How to use the SpellNumber sample function

To use the sample functions to change a number to written text, use one of the methods demonstrated in the following examples:

Method 1: Direct Entry

You can change 32.50 into "Thirty Two Dollars and Fifty Cents" by entering the following formula into a cell:
=SpellNumber(32.50)

Method 2: Cell reference

You can refer to other cells in the workbook. For example, enter the number 32.50 into cell A1, and type the following formula into another cell:
=SpellNumber(A1)

Method 3: Paste Function or Insert Function

To enter a custom function into a worksheet, you can use Paste Function in Excel 2000, or you can use Insert Function in Excel 2002 and in Excel 2003.

Excel 2000

To use Paste Function, follow these steps:
  1. Select the cell that you want.
  2. Click Paste Function on the Standard toolbar.
  3. Under Function category, click User Defined.
  4. Under Function name, click SpellNumber, and then click OK.
  5. Enter the number or cell reference that you want, and then click OK.

Excel 2002 and Excel 2003

To use Insert Function, follow these steps:
  1. Select the cell that you want.
  2. Click Insert Function on the Standard toolbar.
  3. Under Or select a category, click User Defined.
  4. In the Select a function list, click SpellNumber, and then click OK.
  5. Enter the number or cell reference that you want, and then click OK.